Friday, December 15, 2017

C++ Salesperson Salary Ranges - Write a program (using an array of counters) that determines how many of the salespeople earned salaries

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

int main()
{
    int index, salary, grossSales = 1;
    int salaryRange[9] = {0}; // set every element to the same value

    while (true)
    {
        cout << "Enter employee gross sales (-1 to end): ";
            cin >> grossSales;

        if (grossSales == -1)
        {
            break;
        }

        salary = 200 + ((grossSales*9) / 100);
        index = (salary / 100) - 2;

        cout << "Employee commission is " << "$" << salary << endl;

        if (salary > 1000)
            salaryRange[8] = salaryRange[8] + 1;

        else
            salaryRange[index] = salaryRange[index] + 1;

    }

    cout << "\nEmployees in the range: ";

    for (int i = 0; i < 8; i++)
    {
        cout << "\n$" << i*100 + 200 << "-$" << i*100 + 299 << ": " << salaryRange[i];
    }

    if (salaryRange[8])
    {
        cout << "\nOver $1000: " << salaryRange[8];
    }

    cout << endl;


    return 0;

}

No comments:

Post a Comment