Thursday, July 30, 2009

C ++ help please!?

this program should calculate the overtime (if any) and the gross pay.





it just showing me the gross pay in both, the gross output and overtime output. what am i doing wrong? please help me!


this is my code:





#include %26lt;iostream%26gt;


#include %26lt;iomanip%26gt;





using std::cout;


using std::cin;


using std::endl;


using std::fixed;


using std::setprecision;





int main()


{


//declare variables


double hours = 0.0;


double rate = 0.0;


double gross = 0.0;


double overtime = 0.0;





//enter input


cout %26lt;%26lt; "Enter the hours worked: ";


cin %26gt;%26gt; hours;


cout %26lt;%26lt; "Enter the pay rate: ";


cin %26gt;%26gt; rate;





//calculate overtime pay and gross pay


if (hours %26gt; 40.0 || hours %26lt;= 40.0)


{


overtime = (hours * rate) + overtime;


gross = hours *rate;


} //end if


//display output


cout %26lt;%26lt; "Overtime: " %26lt;%26lt; overtime %26lt;%26lt; endl;


cout %26lt;%26lt; "Gross pay: " %26lt;%26lt; gross %26lt;%26lt; endl;


return 0;


} //end of main function

C ++ help please!?
I think your problem is in this line:


overtime = (hours * rate) + overtime;





it should be something like:





overtime = (hours - 40) * rate;
Reply:if (hours %26gt; 40.0 || hours %26lt;= 40.0)


{


overtime = (hours * rate) + overtime;


gross = hours *rate;


} //end if





This condition is always met.





In +overtime, overtime is always 0.0.
Reply:Your if statement is wrong. It lets everything fall through.


No comments:

Post a Comment