Instead of reading in 10 sets of data using a ‘for’ loop, read in and process a
ID: 3685148 • Letter: I
Question
Instead of reading in 10 sets of data using a ‘for’ loop, read in and process a set of values for employee id, previous salary and current salary (all defined as integers) for an indefinite number of times, using a ‘while’ loop and a sentinel value. Stop processing as soon as the user enters a sentinel value (you decide which field should have which value in order to stop the processing. Pick a variable and a value to be the sentinel value and add it in a comment).
Enter data for at least 10 people, with a mix of small increases, fair increases and nice increases.
Send the cin and cout messages to the screen as before. Send all the headings and salary increase information to an output file. Make sure that the output lines up under the headings.
At the end of processing, print the number of employees that were processed and the average increase.
Here is some sample output for your output report.
Employee Id Previous Salary Current Salary Increase Comment
1111 10000 10900 900 Small increase
2222 30000 40000 10000 Fair increase
3333 100000 150000 50000 Nice Increase
The number of people processed is 3.
The average increase is 20300.
Add an edit inside the while loop—if the user enters a current salary less than the previous salary, print an error message and ask him to re-enter the current salary. Keep doing this until he enters a correct current salary.
please need help coding this to c++
Explanation / Answer
#include <iostream>
#include<iomanip.h>
using namespace std;
int main() {
int eid,psal,csal,dif,avg;
int svalue;
int n=0;
cout << “Enter svalue:”;
cin>>svalue;
while (svalue!=-1) {
cout<< “ Enter Employee id:”;
cin>>eid;
n++;
cout <<” Enter previous salary:”;
cin>>psal;
cout<<” Enter current salary:”;
cin>>csal;
if(csal>psal) {
cout<<”Current salary must be greater than previous salary”;
cout <<”Enter current salary:”;
cinn>>csal;
}
else {
cout << “ Employee Id Previous Salary Current Salary “ << eid psal csal;
dif = csal-psal;
cout << “Increase Comment:”;
if(dif>1000 || dif <10000) {
cout << “Small Increase”;
} else if(dif >10000 || dif <50000) {
cout <<”Fair Increase”;
}else if(dif>50000) {
cout <<”Nice Increase”;
int total + = dif
}
}
cout << “ The no of people processed is : “ << n;
avg = total/n;
cout << “ The average increase is : “ << avg;
}