how to solve this question on C++ without using temp! using for loop and if stat
ID: 3741027 • Letter: H
Question
how to solve this question on C++ without using temp! using for loop and if statements.
Sample input / output: nter employee gross sales -1 to end>: 1200 mployee Commission is $184.00 nter employee gross sales -1 to end>: 55006 mployee Commission is $3950.00 nter employee gross sales (-1 to end>: 12540 mployee Commission is $977.80 nter employee gross sales -1 to end>: 4000 mployee Commission is $380.00 nter employee gross sales (-1 to end>: 995 mployee Commission is $169.65 nter employee gross sales -1 to end>: 3645 mployee Commission is $355.15 nter employee gross sales : 2300 mployee Commission is $261.00 nter employee gross sales -1 to end>: 11530 mployee Commission is $907.10 nter employee gross sales (-1 to end>: 14500 mployee Commission is $1115.00 nter employee gross sales : -1 mployees in the range: 100-$199 : 2 $200-$299 : 1 $400-$499 0 $600-$699 0 $900-$999 : 2 300-$399 2 500-$599 : 0 700-$799 0 800-5899 ver $1000: 2Explanation / Answer
/******** C++ Program *******/
#include <bits/stdc++.h>
using namespace std;
int main() {
int range[10]={0};
float grossSale;
float totalSalary=0;
for(int i=1;i!=-1;)
{
cout<<"Enter employee gross sales(-1 to end): ";
cin>>grossSale;
if(grossSale==-1) break;
else
{
totalSalary = 100 + 0.07*grossSale;
if(totalSalary>=100 && totalSalary<=199) range[0]++;
else if(totalSalary>=200 && totalSalary<=299) range[1]++;
else if(totalSalary>=300 && totalSalary<=399) range[2]++;
else if(totalSalary>=400 && totalSalary<=499) range[3]++;
else if(totalSalary>=500 && totalSalary<=599) range[4]++;
else if(totalSalary>=600 && totalSalary<=699) range[5]++;
else if(totalSalary>=700 && totalSalary<=799) range[6]++;
else if(totalSalary>=800 && totalSalary<=899) range[7]++;
else if(totalSalary>=900 && totalSalary<=999) range[8]++;
else if(totalSalary>=1000) range[9]++;
}
}
cout<<" Employees in the range: ";
cout<<"$100-$199: "<<range[0]<<endl;
cout<<"$200-$299: "<<range[1]<<endl;
cout<<"$300-$399: "<<range[2]<<endl;
cout<<"$400-$499: "<<range[3]<<endl;
cout<<"$500-$599: "<<range[4]<<endl;
cout<<"$600-$699: "<<range[5]<<endl;
cout<<"$700-$799: "<<range[6]<<endl;
cout<<"$800-$899: "<<range[7]<<endl;
cout<<"$900-$999: "<<range[8]<<endl;
cout<<"Over $1000: "<<range[9]<<endl;
return 0;
}
/** Input and output ***/
Enter employee gross sales(-1 to end):1200
Enter employee gross sales(-1 to end):55000
Enter employee gross sales(-1 to end): 12540
Enter employee gross sales(-1 to end): 4000
Enter employee gross sales(-1 to end): 995
Enter employee gross sales(-1 to end): 3645
Enter employee gross sales(-1 to end): 2300
Enter employee gross sales(-1 to end): 11530
Enter employee gross sales(-1 to end): 14500
Enter employee gross sales(-1 to end): -1
Employees in the range:
$100-$199: 2
$200-$299: 1
$300-$399: 2
$400-$499: 0
$500-$599: 0
$600-$699: 0
$700-$799: 0
$800-$899: 0
$900-$999: 2
Over $1000: 2
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.