Menu

invalid operands to binary %

2002-10-25
2012-09-26
  • Nobody/Anonymous

    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);
    }

     
    • Nobody/Anonymous

      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

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.