error: expected expression before 'int'

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lordhoban
    New Member
    • Nov 2009
    • 8

    error: expected expression before 'int'

    My program was running fine under visual studio, but I moved it over to Linux, and have run into one problem I have no idea how to fix.

    error: expected expression before 'int'

    (all the following lines cause the error. Obviously it is what I'm doing with the INT that is the problem);

    CEnts = NetPay - int(NetPay);
    numHuns = int(NetPay)/100;

    numHuns = int(NetPay)/1000;
    numTens = int(NetPay) % 100 / 10;
    numOnes = int(NetPay) % 100 % 10;
    RemainDER=int(N etPay) % 100;

    int CEnts3 = int(CEnts);

    I used INT as a way of cutting a float down, eliminating numbers smaller than whole numbers. Any ideas or workarounds?
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    Actually my experience with that error message is that it means something has gone wrong before the actual location where it is reported. Also if it was a problem with the code you have posted then presumably this would give the same error

    Code:
    int main()
    {
        float NetPay = 2233.545f;
        int numHuns = int(NetPay)/1000;
    }
    but this compiles without errors.

    Post a little more of the code for one of the examples.

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      Avoid using floating point for money. Because of rounding, things will never add up correctly.

      Use integers and keep your amounts in pennies.

      You can always display an int with 1234 as a value as $12.34.

      You don't need a decimal point except for the human eyeball.

      Comment

      Working...