Thread: A very simple question... + ERROR.

  1. #1
    Registered User Vber's Avatar
    Join Date
    Nov 2002
    Posts
    807

    A very simple question... + ERROR.

    I receive this error:

    24 C:\WINDOWS\Desktop\oved.c
    invalid operands to binary %

    This is the line:

    //Evaluate the minutes
    mins = ((tops * MIN_PER_TOP) % MIN);


    And this is the code:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    #define MIN_PER_TOP 10     //Minutes per top
    #define MONEY_PER_TOP 6.3  //Money per top
    #define MIN 60             //Minutes 
    #define MIN_PER_HOUR 3600  //Minutes per hour
    
    int main()
    {
        float tops, money, hours, mins;
        
        //Get the tops value
        printf("How many tops? : ");
        scanf("%f",&tops);
        
        //Evaluate the money
        money = tops * MONEY_PER_TOP;
        
        //Evaluate the hours
        hours = (tops * MIN_PER_TOP) / MIN;
        
        //Evaluate the minutes
        mins = ((tops * MIN_PER_TOP) % MIN);
              
        
        printf("\nThe worker made %.1f shekels cuz he made %.1f tops in %.1f hours and %.1f mins \n",money,tops,hours,mins);
        system("pause");
        
        return 0;
    }
    Thanks.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    % only works for integral values. To obtain the remainder of a floating point division, use fmod in math.h.

    -Prelude
    My best code is written with the delete key.

  3. #3
    Registered User Vber's Avatar
    Join Date
    Nov 2002
    Posts
    807

    Wink Thanks for the help, now the app works fine.

    Thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  2. error: template with C linkage
    By michaels-r in forum C++ Programming
    Replies: 3
    Last Post: 05-17-2006, 08:11 AM
  3. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  4. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 05:45 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM