C++ output the highest number

So this program calculates bonus rates for multiple sales persons depending on how much they bring in. I then have to output the total bonus paid, the average bonus paid, and the largest bonus paid. I have everything working up till I have to output the largest bonus paid. I'm not sure how to go about this at all. I've been told to compare the input each time the for loop repeats, but I don't know how to do that.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <iomanip>
#include <conio.h>

using namespace std;

int main()
{
    int noPeople=0;
    char salesMember[50];
    double salesIncome, bonusRate, bonusTotal=0, averageBonus;

    cout << "\t\t\tBonus Rates";
    cout << "\n\nEnter number of sales people : ";
    cin >> noPeople;

    for (int x=1; x<=noPeople; x++) {

        cout << "\n\nEnter name of sales person : ";
        cin >> salesMember;

        cout << "Enter sales income : ";
        cin >> salesIncome;

        if (salesIncome <= 5000) {bonusRate = salesIncome *  0.000;}
        else if (salesIncome > 5000 && salesIncome <= 25000) {bonusRate = salesIncome * 0.15;}
        else if (salesIncome > 25000 && salesIncome <= 40000) {bonusRate = salesIncome * 0.20;}
        else {bonusRate = salesIncome * 0.50;}

        cout << "Bonus due : " << bonusRate;

        bonusTotal = bonusTotal + bonusRate;
        averageBonus = bonusTotal / noPeople;

    }

    cout << "\n\nTotal bonus amount paid : " << bonusTotal;
    cout << "\nAverage bonus amount paid : " << averageBonus;

    _getche();
    return 0;
}
1
2
3
4
5
6
7
8
int max = array[0]; // start with max = first element

     for(int i = 1; i<length; i++)//length is array size
     {
          if(array[i] > max)
                max = array[i];//highest value in array
     }
 


int, double, whatever flavor you need same boilerplate.
Last edited on
Nevermind, sorted it.

Sorry mobotus, hadn't even noticed your reply when you I posted this. Thanks for the reply, was able to get it working in the end up. Thanks.
Last edited on
Topic archived. No new replies allowed.