This is the output needed:
Enter hours worked: (-1 to end): 39
Enter hourly rate of the worker ($00.00): 10.00
Salary is $390.00
Enter hours worked (-1 to end): 40
Enter hourly rate of the worker ($00.00): 10.00
Salary is $400.00
Enter hours worked (-1 to end): 41
Enter hourly rate of the worker ($00.00): 10.00
Salary is $415.00
Enter hours worked (-1 to end): -1
Here is my code....Am I way off?
#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 = 40.0;
double rate = 10.0;
double gross = 0.0;
double overtime = 1.5;
//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){
overtime = (hours-40) * rate * 1.5;
gross = 40 * rate + overtime;
}
else{
gross = rate * hours;
}
//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;
system ("pause");
return 0;
} //end of main function
C++ Gross Pay Program Help?
because you're resetting gross every time you go through it. say gross = 40 * rate + overtime;
and
gross = 40 * rate;
you'll also want to initialize all your variables to 0 in the start of the program. it's very very bad coding style to do otherwise, since you're resetting them anyway.
Reply:Aside from the Windows-specific system("pause") business, it looks pretty good. If you tell us in what way it appears to not work, we will be better able to help you.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment