Try to set a while statement with a loop and a break

#include <iostream>
#include <iomanip>
#include <Windows.h>

using namespace std;

int main()
{
double hrsWorked = 0.0;
double rate = 0.0;
double overtime = 0.0;
double overtimePay = 0.0;
double salary = 0.0;


while (hrsWorked <= 40)
{
cout << "Enter number of hours worked (-1 to end): ";
cin >> hrsWorked;

if (hrsWorked == -1)
{
return 0;
}
cout << ("Enter hourly rate of the worker ($00.00): ");
cin >> rate;

salary = hrsWorked * rate;

if (hrsWorked <= 40)
{
cout << "Weekly salary is :$ ";
cin >> salary;
}

if (hrsWorked > 40)
{
overtime = hrsWorked - 40;
overtimePay = overtime * rate * 1.5;
salary = salary + overtimePay;

cout << fixed << setprecision(2) << "Weekly salary is : $" << salary << endl;

cout << "Enter number of hours worked (-1 to end): ";
cin >> hrsWorked;
}

} // end while

system("pause");
return 0;
}//end of main function

I ma trying to run this with a while loop with the first cout<< and cin>> outside the loop to calculate the overtime for hours worked >40. I am currently havving issues when the cout and cin it outside of the loop.
Last edited on
Is there a question?
Topic archived. No new replies allowed.