Using C Write a program to allow the user to enter id number

Using C++


Write a program to allow the user to enter id numbers, a code and appropriate information to compute weekly salaries. The code entered will be one of the following:

s   salaried employee receives a yearly pay amount
c    commissioned employee – receives a weekly base amount of $185.00 plus 5.3% of all sales over 3000 and an additional 2.4% for sales over 5000
h   receive a weekly pay based on hourly wage and hours worked per week

The user will continue to enter employee information until an id code of 0 is entered.

Submit your source code and three printouts using the input data below.

35798 s 52000
47654 c 7000
54632 h 20.00 30   

Solution

Please find the required program along with its output. Please see the comments against each line to understand the step.


#include <iostream>
#include <string>

using namespace std;

int main()
{
int id;
char c;
  
while(true) {
  
cout << \"\ \ Enter user id; 0 to exit\" << endl;
cin >> id;
  
if(id==0)
break;
  
cout << \"Enter code: \" << endl;
cin >> c;
  
if(c==\'S\'||c==\'s\'){
int pay;
cout << \"Enter yearly pay amount\" << endl;   
cin >> pay; //read yearly pay
  
double wPay = pay/58; //to get the weekly payment divide yearly pay by 58 (total weeks in a year)
cout << \"\ Employee id: \"<< id <<\"\\t Weekly pay = \" << wPay << endl;
  
} else if(c==\'C\'||c==\'c\'){
int sale;
cout << \"Enter total sales: \" << endl;   
cin >> sale;

double wPay = 185; //initialize with weekly base amount;

if(sale > 5000){ //if sales is more than 5000, provide 2.4% bonus
wPay = wPay + ((5000 - sale) * 0.024);
}

if(sale > 3000){ //if sales is more than 3000, provide 5.3% bonus
wPay = wPay + ((sale - 3000) * 0.053);
}

cout << \"\ Employee id: \"<< id <<\"\\t Weekly pay = \" << wPay << endl;

} else if(c==\'H\'||c==\'h\'){
  
double hw, pw;
cout << \"Enter hourly wage: \" << endl;   
cin >> hw;
  
cout << \"Enter hours worked per week: \" << endl;   
cin >> pw;
  
double wPay = hw * pw; //calculate weekly pay by hourly wage * hours worked per week ;

cout << \"\ Employee id: \"<< id <<\"\\t Weekly pay = \" << wPay << endl;
}
  
  
}
}

---------------------------------------

OUTPUT:

Enter user id; 0 to exit   
35798
Enter code:
s
Enter yearly pay amount
52000

Employee id: 35798 Weekly pay = 896


Enter user id; 0 to exit   
47654
Enter code:
c
Enter total sales:   
7000   

Employee id: 47654 Weekly pay = 349


Enter user id; 0 to exit   
54632
Enter code:
h
Enter hourly wage:   
20   
Enter hours worked per week:   
30   

Employee id: 54632 Weekly pay = 600


Enter user id; 0 to exit   
0   

Using C++ Write a program to allow the user to enter id numbers, a code and appropriate information to compute weekly salaries. The code entered will be one of
Using C++ Write a program to allow the user to enter id numbers, a code and appropriate information to compute weekly salaries. The code entered will be one of
Using C++ Write a program to allow the user to enter id numbers, a code and appropriate information to compute weekly salaries. The code entered will be one of

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site