Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#include <iostream> #include <fstream> #include <iomanip> using namespace std; v

ID: 3640612 • Letter: #

Question


#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;

void ProcessCounter(int counters[]);
double GetSale();
double GetSalary(double sale);
int GetRange(double salary);
bool MoreEmployee();
void Print(int counters[]);
void PrintLine(ostream& out);

const int MAX = 9;

int main()
{
int counters[MAX];

ProcessCounter(counters);
Print(counters);

system("pause");
return 0;
}

void ProcessCounter(int counters[])
{
double sale, salary;
int index;
do
{
sale = GetSale();
salary = GetSalary(sale);
index = GetRange(salary);

cout << index << endl;

counters[index]++;
} while (MoreEmployee());
}
double GetSale()
{
double sale;
cout << "What is your sale ";
cin >> sale;

return sale;
}

double GetSalary(double sale)
{
double salary;
return salary = (sale * 0.09) + 200;
}

int GetRange(double salary)
{
if ( salary > 200 && salary < 299)
{
return 0;
}
else if (salary > 300 && salary < 399)
{
return 1;
}
else if (salary > 400 && salary < 499)
{
return 2;
}
else if (salary > 500 && salary < 599)
{
return 3;
}
else if (salary > 600 && salary < 699)
{
return 4;
}
else if (salary > 700 && salary < 799)
{
return 5;
}
else if (salary > 800 && salary < 999)
{
return 6;
}
else if (salary > 900 && salary < 999)
{
return 7;
}
else
{
return 8;
}
}

bool MoreEmployee()
{
char ans;

cout << "Have more employees? ";
cin >> ans;
ans = toupper(ans);

if ( ans == 'Y')
{
return true;
}
else
{
return false;
}
}
void PrintLine(ostream& out)
{
for ( int i = 0 ; i < 50 ; i++)
{
out << "=";
}
out << endl;
}

void Print(int counters[])
{
for (int i = 0 ; i < counters[] ; i++)
{
cout << counters[i] << " " << endl;
}
}

Explanation / Answer

PS: Please rate the answer You had forgotten to initialize the counters array to zeros. And you had one more mistake in the print function. I've corrected and here is the code. #include #include #include using namespace std; void ProcessCounter(int counters[]); double GetSale(); double GetSalary(double sale); int GetRange(double salary); bool MoreEmployee(); void Print(int counters[]); void PrintLine(ostream& out); int countPerSalary[9]; const int MAX = 9; int main() { int counters[MAX]; for(int i=0; i 500 && salary < 599) { return 3; } else if (salary > 600 && salary < 699) { return 4; } else if (salary > 700 && salary < 799) { return 5; } else if (salary > 800 && salary < 999) { return 6; } else if (salary > 900 && salary < 999) { return 7; } else { return 8; } } bool MoreEmployee() { char ans; cout > ans; ans = toupper(ans); if ( ans == 'Y') { return true; } else { return false; } } void PrintLine(ostream& out) { for ( int i = 0 ; i < 50 ; i++) { out