First up thanks to the guys who pointed out my error last week.
Now I was wondering If I could get some help with this problem because again I have fallen into trouble. Basically im using the while statement to loop a program but dont know how to loop back to the request of Enter hours worked or (-1 to end) : 39. I cant put it in the while statement as it contains the condition that activates the while statement, if you see what I mean?
Im trying to get a process like so
Sample screen input/ouput
Enter hours worked or (-1 to end) : 39
Enter hourly rate of worker (£00.00) : 10.00
Salary is £390.00
Enter hours worked or (-1 to end) : 40
Enter hourly rate of worker (£00.00) : 10.00
Salary is £400.00
Enter hours worked or (-1 to end) : 41
Enter hourly rate of worker (£00.00) : 10.00
Salary is £415.00
Enter hours worked or (-1 to end) : -1
But im getting this....
Enter hours worked or (-1 to end) : 39
Enter hourly rate of worker (£00.00) : 10.00
Salary is £390.00
Enter hourly rate of worker : 10.00
Salary is 390.00 (it uses my original value of hours and i dont know how to allow the user to input a new value of hours worked for a new worker.
Heres my program...
[code=cpp]
#include <iostream>
#include <cmath>
using std::cout;
using std::cin;
using std::endl;
int main ()
{
double hours;
double Pay_per_hour;
double Total_Pay;
cout << "Enter hours worked or -1 to end: ";
cin >> hours;
while (hours != -1)
{
cout << "Enter hourly rate of the worker ";
cin >> Pay_per_hour;
if (hours <= 40)
Total_Pay = hours * Pay_per_hour;
else
Total_Pay = ( (hours - 40) * 15 ) + 400;
cout << "Salary is " << Total_Pay << endl;
}
return 0;
} // end main[/code]
Now I was wondering If I could get some help with this problem because again I have fallen into trouble. Basically im using the while statement to loop a program but dont know how to loop back to the request of Enter hours worked or (-1 to end) : 39. I cant put it in the while statement as it contains the condition that activates the while statement, if you see what I mean?
Im trying to get a process like so
Sample screen input/ouput
Enter hours worked or (-1 to end) : 39
Enter hourly rate of worker (£00.00) : 10.00
Salary is £390.00
Enter hours worked or (-1 to end) : 40
Enter hourly rate of worker (£00.00) : 10.00
Salary is £400.00
Enter hours worked or (-1 to end) : 41
Enter hourly rate of worker (£00.00) : 10.00
Salary is £415.00
Enter hours worked or (-1 to end) : -1
But im getting this....
Enter hours worked or (-1 to end) : 39
Enter hourly rate of worker (£00.00) : 10.00
Salary is £390.00
Enter hourly rate of worker : 10.00
Salary is 390.00 (it uses my original value of hours and i dont know how to allow the user to input a new value of hours worked for a new worker.
Heres my program...
[code=cpp]
#include <iostream>
#include <cmath>
using std::cout;
using std::cin;
using std::endl;
int main ()
{
double hours;
double Pay_per_hour;
double Total_Pay;
cout << "Enter hours worked or -1 to end: ";
cin >> hours;
while (hours != -1)
{
cout << "Enter hourly rate of the worker ";
cin >> Pay_per_hour;
if (hours <= 40)
Total_Pay = hours * Pay_per_hour;
else
Total_Pay = ( (hours - 40) * 15 ) + 400;
cout << "Salary is " << Total_Pay << endl;
}
return 0;
} // end main[/code]
Comment