I want to use modulo, so that i can use the remainder of a quotient. but this (invalid operands to binary %) comes up when I compile. The program is a 'C' console application.
my funtion looks like this
void total_amount(float total, int *pennies, int *nickels, int *dimes, int *quarters)
{
float first, second, third;
*quarters=total/(.25);
first=total%(.25);
*dimes=first/(.10);
second=first%(.10);
*nickels=second/(.05);
third=second%(.05);
*pennies=third/(.01);
}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I want to use modulo, so that i can use the remainder of a quotient. but this (invalid operands to binary %) comes up when I compile. The program is a 'C' console application.
my funtion looks like this
void total_amount(float total, int *pennies, int *nickels, int *dimes, int *quarters)
{
float first, second, third;
*quarters=total/(.25);
first=total%(.25);
*dimes=first/(.10);
second=first%(.10);
*nickels=second/(.05);
third=second%(.05);
*pennies=third/(.01);
}
dividing by .25 is the same as multiplying by 4
*quarters=total/(.25); this is equivalent to
*quarters=total*4;
same with all the rest
to use % you need (int) %(int) as i understand
eg
3%4 is 3
6%4 is 2