I am having a problem with this program. I think I\'ve done it correctly but it
ID: 3617409 • Letter: I
Question
I am having a problem with this program. I think I've done it correctly but it keeps giving me an error. When I run it, itrepeats the invalid number statement and never stops. Please do notgive me the answer! I want hints so I can figure out how I can fixthe problem.Here's what I did...
#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{
int paycode = 0,
hours = 0,
pieces = 0;
double salary = 0.0,
wage = 0.0,
sales = 0.0,
wageperpiece = 0.0;
do {
salary = 0.0;
paycode = 0;
cout << "Enter paycode (-1 to end): ";
switch (paycode) {
case 1:
salary = 0.0;
cout << "Manager selected. Enterweekly salary: ";
cin >> salary;
cout << "The manager's pay is : $"<< setprecision(2) << fixed << salary <<endl;
break;
case 2:
wage = 0.0;
cout << "Hourly workerselected. Enter the hourly salary: ";
cin >> wage;
hours = 0;
cout << "Enter the total hoursworked: ";
if (hours <= 40)
{
salary = hours * wage;
}
else
{
salary = 40 * wage + (hours-40) * wage *1.5;
}
cout << "Worker's pay is $" <<setprecision(2) << fixed << salary << endl;
break;
case 3:
sales = 0.0;
cout << "Commission workersselected. Enter gross weekly sales: ";
cin >> sales;
salary = sales*.05+250;
cout << "Commission worker's pay is$" << setprecision(2) << fixed << salary <<endl;
break;
case 4:
pieces = 0;
cout << "Pieceworkerselected. Enter number of pieces: ";
cin >> pieces;
wageperpiece = 0.0;
cout << "Enter wage per pieces:";
salary = pieces*wageperpiece;
cout << "Pieceworkers pay is $"<< setprecision(2) << fixed << salary <<endl;
break;
case -1:
cout << endl << "Good-Bye!"<< endl;
break;
default:
cout << "Invalid number! Please tryagain. " << endl;
break;
}
} while(paycode != -1);
system("pause");
return 0;
}
Here's the question....
A company pays its employees as managers (who receive a fixed weekly salary), hourly
workers (who receive a fixed hourly wage for up to the first 40 hours they work and
time-and-a-half, i.e. 1.5 times their hourly wage, for overtime hours worked), commission
workers (who receive $250 plus 5% of their gross weekly sales), or pieceworkers (who
receive a fixed amount of money for each item they produce-each pieceworker in the
company works only on one type of item). Write a program to compute the weekly pay for each
employee. You do not know the number of employees in advance. Each type of employee has its
own pay code: Managers have code 1, hourly workers have code 2, commission workers 3 and
pieceworkers 4. Use a switch to compute each employee's pay according to his/her paycode.
Within the switch, prompt the user to enter the appropriate facts your program needs
to calculate each employee's pay according to the paycode.
Expected Output:
Enter paycode (-1 to end): 100
Invalid number! Please try again.
Enter paycode (-1 to end): 1
Manager selected.
Enter weekly salary: 244
The manager's pay is $244.00
Enter the next paycode (-1 to end): 2
Hourly worker selected.
Enter the hourly salary: 12.30
Enter the total hours worked: 39
Worker's pay is $479.70
Enter the next paycode (-1 to end): 3
Commission worker selected.
Enter gross weekly sales: 8000
Commission worker's pay is $650.00
Enter the next paycode (-1 to end): 4
Pieceworker selected.
Enter number of pieces: 2345
Enter wage per piece: 1.75
Pieceworker's pay is $4103.75
Enter the next paycode (-1 to end): -1
Good-bye!
Explanation / Answer
Its Working fine, you have to usecin for taking input from console instead ofprompt. I am putting the running code here, i just change the prompt tocin Please Check and Rate Me :)Thanks #include #include #include using namespace std; int main () { int paycode = 0, hours = 0, pieces = 0; double salary = 0.0, wage = 0.0, sales = 0.0, wageperpiece = 0.0; do { salary = 0.0; paycode = 0; coutpaycode; //paycode = prompt("Enter paycode (-1 to end): ",0); switch (paycode) { case 1: //salary = prompt("Managerselected. Enter weekly salary: ", 0.0); coutsalary; coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.