473,237 Members | 1,258 Online

# One dimensional array using an array of counters

I'm having ALOT of trouble understanding this (C++)..and i don't think i'm even close to getting this right. Please help. The problem reads as follows:

Use a one dimensional array to solve. A company pays on a commission basis. the salespeople receive \$200 per week plus 9 percent of their gross sales for that week. (salesperson grosses 5000 in a week receives 200 plus 9 percent of 5000, total of 650) Write a program, using an array of counters, that determines how many of the salespeople earned salaries in each of the following ranges (assume that each salesperson's salary is truncated to an integer amount)
a) \$200-299
b)\$300-399
c)\$400-499
d)\$500-599
e)\$600-699
f)700-799
g)800-899
h)\$900-999
i)\$1000 and over

this is what i have so far:
#include <iostream>
using std::cout;
using std::cin;
using std::endl;

#include <iomanip>
using std::setw;
int main()
{
const int frequencySize = 11;
int frequency[ frequencySize ] = {};
int grossSales;
int total;

{

cout << "Enter employees gross sales: ";
cin >> grossSales;
cout << "Salary: " << grossSales * .09 + 200;

cout << "\nSalary:" << endl;}

for ( int count = 2; count < frequencySize; count++ )
{
if ( count == 2 )
cout << "\$200-299: ";
else if ( count == 1000 )
cout << " \$1000 ";
else
cout << "\$" << count * 100 << "-" << ( count * 100 ) + 99 << ": ";

for ( int stars = 0; stars < frequency[ count ]; stars++ )
cout << '*';

cout << endl;

}

return 0;

}
i can't get the stars to appear beside the range and i don't know how to keep the loop going after the first salary is entered (while loop?)
Dec 6 '07 #1
1 6317
gpraghuram
1,275 Expert 1GB
I'm having ALOT of trouble understanding this (C++)..and i don't think i'm even close to getting this right. Please help. The problem reads as follows:

Use a one dimensional array to solve. A company pays on a commission basis. the salespeople receive \$200 per week plus 9 percent of their gross sales for that week. (salesperson grosses 5000 in a week receives 200 plus 9 percent of 5000, total of 650) Write a program, using an array of counters, that determines how many of the salespeople earned salaries in each of the following ranges (assume that each salesperson's salary is truncated to an integer amount)
a) \$200-299
b)\$300-399
c)\$400-499
d)\$500-599
e)\$600-699
f)700-799
g)800-899
h)\$900-999
i)\$1000 and over

this is what i have so far:
#include <iostream>
using std::cout;
using std::cin;
using std::endl;

#include <iomanip>
using std::setw;
int main()
{
const int frequencySize = 11;
int frequency[ frequencySize ] = {};
int grossSales;
int total;

{

cout << "Enter employees gross sales: ";
cin >> grossSales;
cout << "Salary: " << grossSales * .09 + 200;

cout << "\nSalary:" << endl;}

for ( int count = 2; count < frequencySize; count++ )
{
if ( count == 2 )
cout << "\$200-299: ";
else if ( count == 1000 )
cout << " \$1000 ";
else
cout << "\$" << count * 100 << "-" << ( count * 100 ) + 99 << ": ";

for ( int stars = 0; stars < frequency[ count ]; stars++ )
cout << '*';

cout << endl;

}

return 0;

}
i can't get the stars to appear beside the range and i don't know how to keep the loop going after the first salary is entered (while loop?)

HI,

Thanks
Raghuram
Dec 6 '07 #2