Why cant I MOD in Code Warrior

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ALi Shaikh
    New Member
    • Sep 2007
    • 18

    Why cant I MOD in Code Warrior

    When ever I put in the % symbol it gives me stupid errors but if I change the % to a - or +,*,/ it works here is the code.
    Code:
    ..  
    //Price of Pizza's 
    #include<iostream.h>
    void main()
    {
    	float inch;   
    	float fin; 
    	
    cout<<endl;
    cout<<"Enter your Height ";
    cin>> inch;
    fin = inch % 12;
    cout<<"Here is your hieght "<<inch/12<<fin<< " in feet and inches ";
    }
    ..
  • Studlyami
    Recognized Expert Contributor
    • Sep 2007
    • 464

    #2
    change inch from float into an int. You can't use the % operator with float type variables.

    Comment

    • ALi Shaikh
      New Member
      • Sep 2007
      • 18

      #3
      What do I do then because i need this by sunday

      Comment

      • Studlyami
        Recognized Expert Contributor
        • Sep 2007
        • 464

        #4
        Do you need to calculate 16.5 inches? I would just put it as an int or cast it to an int. There are work arounds, but i don't know any off the top of my head. You can google this topic and find code to get around this issue.

        Comment

        • Ganon11
          Recognized Expert Specialist
          • Oct 2006
          • 3651

          #5
          Check this out - looks like there's a function in the cmath header file (or math.h if you're in C) that will do what you need.

          Comment

          • ALi Shaikh
            New Member
            • Sep 2007
            • 18

            #6
            Sorry Studlyami I didnt fully read your reply.
            Well i changed float to int and now all my problems are solved THANKS!!

            Comment

            • Studlyami
              Recognized Expert Contributor
              • Sep 2007
              • 464

              #7
              your welcome. If you need to use floating points read the link ganon gave you. the fmod function (in math.h) is super easy to use and give s you the same result as the % operator.

              Comment

              Working...