Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- using namespace std;
- void getJudgeData(int);
- void calcScore(double [], double&);
- int findLowest(double []);
- int findHighest(double []);
- double score[4];
- int main(void) {
- double final_score; // Final result after calculations.
- for (int i = 1; i <= 5; ++i) {
- getJudgeData(i);
- }
- calcScore(score, final_score);
- cout << "Final score: " << final_score;
- cin.get();
- return 0;
- }
- /* Promps for a score to be entered. */
- void getJudgeData(int judge) {
- double input;
- bool loop = false;
- while (loop == false) {
- cout << "Judge " << judge << ", enter your score: ";
- cin >> score[--judge];
- input = score[--judge];
- if (input < 0 || input > 10) {
- cout << score << " is an invalid entry." << endl;
- cin.ignore();
- cin.get();
- system("CLS");
- }
- else {
- cout << "Thank you." << endl;
- loop = true;
- }
- cin.ignore();
- cin.get();
- system("CLS");
- }
- }
- /* Calculates the average of the score minus the highest and lowest numbers. */
- void calcScore(double score[], double &final_score) {
- final_score = ((score[0] + score[1] + score[2] + score[3] + score[4]) -
- (findLowest(score) +
- findHighest(score))) / 3;
- }
- /* Finds the lowest of 5 numbers. */
- int findLowest(double score[]) {
- int lowest;
- if (score[0] < lowest)
- lowest = score[0];
- if (score[1] < lowest)
- lowest = score[1];
- if (score[2] < lowest)
- lowest = score[2];
- if (score[3] < lowest)
- lowest = score[3];
- if (score[4] < lowest)
- lowest = score[4];
- return lowest;
- }
- /* Finds the highest of 5 numbers. */
- int findHighest(double score[]) {
- int highest = 0;
- if (score[0] > highest)
- highest = score[0];
- if (score[1] > highest)
- highest = score[1];
- if (score[2] > highest)
- highest = score[2];
- if (score[3] > highest)
- highest = score[3];
- if (score[4] > highest)
- highest = score[4];
- return highest;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement