Problem: Write a program that calculates the average of a group of test scores, where the lowest score in the group is dropped. It should use the following functions:void getScore()
should ask the user for a test score, store it in a reference parameter variable, and validate it. This function should be called by main once for each of the 5 scores to be entered.
void calcAverage()
should calculate and display the average of the 4 highest scores. This function should be called just once by main, and should be passed the 5 scores.
int findLowest()
should find and return the lowest of the 5 scores passed to it. It should be called by calcAverage, which uses the function to determine one of the 5 scores to drop.
Validation: Don't accept test scores lower than 0 or higher than 100.
This is what I got so far. I cant use arrays since I havent gotten that far yet and please if you can explain to me what is going on so I can better understand the syntax, etc.
#include <iostream>
using namespace std;
void getScore(double s1, double s2, double s3, double s4, double s5);
void calcAverage(double s1, double s2, double s3, double s4, double s5);
int findLowest(double, double, double, double, double);
int main();
void getScore(double s1, double s2, double s3, double s4, double s5)
{
cout << "Please enter 5 Test Scores 0 through 100: ";
cin >> s1 >> s2 >> s3 >> s4 >> s5;
while (s1 < 0 || s1 > 100 && s2 < 0 || s2 > 100 && s3 < 0 || s3 > 100 &&
s4 < 0 || s4 > 100 && s5 < 0 || s5 > 100)
{
cout << "You have entered an invalid number\n";
cout << "Please enter number 0 through 100 for each test score: ";
cin >> s1 >> s2 >> s3 >> s4 >> s5;
}
}
void getAverage(double s1, double s2, double s3, double s4, double s5)
{
double sum,
low,
average;
sum = s1 + s2 + s3 + s4 + s5;
low = sum - findLowest(double lowest);
average = low / 4;
}
int findLowest(double s1, double s2, double s3, double s4, double s5)
{
double lowest,
least;
if (s1 < least) least = lowest;
if (s2 < least) least = lowest;
if (s3 < least) least = lowest;
if (s4 < least) least = lowest;
if (s5 < least) least = lowest;
return lowest;
}