Here is my example.. It is nothing like the one you're working on..
Code:
/* This program computes the amount of employees
* who receive a salary in a set number of ranges.
*
* Assignment 4.10
*/
#include <iostream>
#include <iomanip>
using std::cout;
using std::cin;
using std::endl;
double calculateSalary (double totalEarned){
return ((totalEarned*0.09) + 200.0);
}
int main() //begins program execution
{
double earnings = 0.0;
/* allways make room for one more than your index count */
int pay[]= {0,0,0,0,0,0,0,0}; /* for ease we initialize it as 0 */
while (true)
{
cout << "Enter total sales for employee";
cout << " (Enter -1 to stop and tabulate) : ";
cout.flush();
cin >> earnings;
if(earnings == -1.0)
break;
for(int i = 0, amount=300; i < 8; ++i, amount+=100)
if(earnings < amount)
{
pay[i] = pay[i] + 1;
break;
}
cout << "Here is the total salary of employee: $"
<< calculateSalary(earnings) << endl;
}
cout << "The earnings are as follows:" << endl;
for(int i=0, amount=300; i < 8; ++i, amount+=100)
cout << "(" << amount-100 << " <= Amount < " << amount
<< ") Count: " << pay[i] << endl;
return 0;
}