Number of judges programme test
unknown
plain_text
2 years ago
1.3 kB
3
Indexable
Never
#include <iostream> #include <iomanip> #include <cmath> using namespace std; int number_judges; double mark, sum = 0, final_mark, currentJudge; 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 currentJudge = 0; currentJudge < number_judges; currentJudge++) { cout << "Enter the mark given by judge " << currentJudge + 1 << ": "; cin >> mark; while ((mark < 0.0) || (mark > 10.0)) { cout << "Error - Enter the mark given by judge " << currentJudge + 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; }