-
Notifications
You must be signed in to change notification settings - Fork 0
/
Assignment 6.txt
91 lines (76 loc) · 2.54 KB
/
Assignment 6.txt
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*Student Name: Arno Dunstatter
Course Name: Programming Fundamentals
Course Number: CS1336
Section: 001
Due Date: 4/16/20
Date Completed: 4/13/20
Date Submitted: 4/13/20 */
#include <iostream>
using namespace std;
//first our prototypes
void getJudgeData(double&);
double findLowest(double, double, double, double, double);
double findHighest(double, double, double, double, double);
void calcScore(double, double, double, double, double);
//main integrates our two main functions
int main()
{
double score [5] = {}; //our scores will be stored in an array
for (int i = 0; i <= 4; ++i)
{
getJudgeData(score[i]);
}
cout << "The final score was ";
calcScore(score[0], score[1], score[2], score[3], score[4]); //passes our values from our array to the function
cout << ".\n";
return 0;
}
void getJudgeData(double& score)
{
//prompt user for input
cout << "Please enter the judge's given score: ";
cin >> score;
while (score < 0 || score > 10) //performs validation. Score must be between 0 and 10, inclusive
{
cout << "That score was not valid. The score should be between 0 and 10. Please re-enter the judge's given score: ";
cin >> score;
}
}
//this will be called by calcScore
double findLowest(double score1, double score2, double score3, double score4, double score5) //uses a simple algorithm to return the lowest value from 5 given values
{
double score[5] = { score1, score2, score3, score4, score5 };
double lowest = score1;
for (int i = 1; i <= 4; ++i)
{
if (lowest > score[i])
lowest = score[i];
}
return lowest;
}
//this will be called by calcScore
double findHighest(double score1, double score2, double score3, double score4, double score5) //uses a simple algorithm to return the highest value from 5 given values
{
double score[5] = { score1, score2, score3, score4, score5 };
double highest = score1;
for (int i = 1; i <= 4; ++i)
{
if (highest < score[i])
highest = score[i];
}
return highest;
}
void calcScore(double score1, double score2, double score3, double score4, double score5)
{
double score [5] = { score1, score2, score3, score4, score5 }; //makes cycling through the data easier
double lowest = findLowest(score1, score2, score3, score4, score5);
double highest = findHighest(score1, score2, score3, score4, score5);
double sum = 0, scoreFinal;
for (int i = 0; i <= 4; ++i) //this will add all of our scores to sum
{
sum += score[i];
}
sum = sum - highest - lowest; //this removes the highest and the lowest score from our sum
scoreFinal = sum / 3; //averages the three middle scores
cout << scoreFinal;
}