Number of judges programme

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.3 kB
2
Indexable
Never
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int number_judges;
double mark, sum = 0, final_mark;

int main()
{
    cout << "\n Enter the number of judges (4 to 8): " << endl;
    cin >> number_judges;

    while (number_judges < 4 || number_judges > 8)
    {
        cout << "\nError - Please Enter number of judges again. Make sure that the number of judges is between (4 and 8):" << endl;
        cin >> number_judges;
    }
    double highest_mark = 0.0, lowest_mark = 10.0;
    for (int i = 0; i < number_judges; i++)
    {
        cout << "Enter the mark give by judge " << i + 1 << ": ";
        cin >> mark;

        while ((mark < 0.0) || (mark > 10.0))
        {
            cout << "Error - Enter the mark given by judge " << i + 1 << " (0.0 to 10.0): ";
            cin >> mark;
        }

        if (mark > highest_mark)
        {
            highest_mark = mark;
        }
        if (mark < lowest_mark)
        {
            lowest_mark = mark;
        }
        sum += mark;
    }

    final_mark = (sum - highest_mark - lowest_mark) / (number_judges - 2);
    cout << fixed << setprecision(2) << "The total marks given by all judges is: " << final_mark << endl;
}