Vote count:
0
So, my simple program calculates an employees total salary which is $200 + commission. The commission is 9% of their gross sales. So, the program asks for the gross sale of an employee and keeps asking until I use sentinel to stop.
Then I display the number of people that recieved salaries in a certain set of range, and then use asterisks to mark how many people recieved salaries in said range. Finally I also display the total salary by adding recieved salary and total commission by adding all the commissions. Code below:
#include <iostream>
#include <cmath>
using namespace std;
const int SENTINEL = -1;
int main(){
int salary = 200, total_salary_employee, total_salary=0, gross, commission, total_commission=0, counter[9];
int i;
while(gross != SENTINEL){
cout << "Enter gross sale for employee (-1 to stop): ";
cin >> gross;
if(gross == SENTINEL) break;
if(gross < SENTINEL){
cout << "\nError!\nPlease enter a correct value.\n" << endl;
continue;
}
else{
commission = 0.09 * gross;
total_salary_employee = salary + commission;
total_salary += total_salary_employee;
total_commission += commission;
if((total_salary > 200) && (total_salary < 300)){
counter[1] += 1;
}
else if((total_salary >= 300) && (total_salary < 400)){
counter[2] += 1;
}
else if((total_salary >= 400) && (total_salary < 500)){
counter[3] += 1;
}
else if((total_salary >= 500) && (total_salary < 600)){
counter[4] += 1;
}
else if((total_salary >= 600) && (total_salary < 700)){
counter[5] += 1;
}
else if((total_salary >= 700) && (total_salary < 800)){
counter[6] += 1;
}
else if((total_salary >= 800) && (total_salary < 900)){
counter[7] += 1;
}
else if((total_salary >= 900) && (total_salary < 1000)){
counter[8] += 1;
}
else{
counter[9] += 1;
}
}
};
cout << "----------------------------------------------------------------------";
cout << "\n" << endl;
cout << "Element\t\t" << "# of Persons\t\t" << "Histogram";
cout << "\n";
cout << "$200 - $299\t\t" << counter[1] << "\t\t" << for(i = 0; i < counter[1]; i++){ cout << "*"; };
cout << "\n";
cout << "$300 - $399\t\t" << counter[2] << "\t\t" << for(i = 0; i < counter[2]; i++){ cout << "*"; };
cout << "\n";
cout << "$400 - $499\t\t" << counter[3] << "\t\t" << for(i = 0; i < counter[3]; i++){ cout << "*"; };
cout << "\n";
cout << "$500 - $599\t\t" << counter[4] << "\t\t" << for(i = 0; i < counter[4]; i++){ cout << "*"; };
cout << "\n";
cout << "$600 - $699\t\t" << counter[5] << "\t\t" << for(i = 0; i < counter[5]; i++){ cout << "*"; };
cout << "\n";
cout << "$700 - $799\t\t" << counter[6] << "\t\t" << for(i = 0; i < counter[6]; i++){ cout << "*"; };
cout << "\n";
cout << "$800 - $899\t\t" << counter[7] << "\t\t" << for(i = 0; i < counter[7]; i++){ cout << "*"; };
cout << "\n";
cout << "$900 - $999\t\t" << counter[8] << "\t\t" << for(i = 0; i < counter[8]; i++){ cout << "*"; };
cout << "\n";
cout << "$1000 and above\t\t" << counter[9] << "\t\t" << for(i = 0; i < counter[9]; i++){ cout << "*"; };
cout << "\nTotal salary: " << total_salary;
cout << "\nTotal commission: " << total_commission;
return 0;
}
Problem I'm having says:
[Error] expected primary-expression before 'for'
and
[Error] expected ';' before 'for'
and
[Error] expected ';' before ')' token
Expected output:
Element..............# of person..............Histogram
$200-$299...............8...........................********
and the list goes on like that. The number 8 is only an example and the dots are to show that the output is in table form I don't know how to space them properly using this editor.
Can you please show me where and what my mistake is? And what would be a better and shorter way to write this?
Error message saying expected main function before for
Aucun commentaire:
Enregistrer un commentaire