Lowest Score Drop - reference parameter variable, values, etc.
Hey, everyone. I'm having a problem with a program and I'm hoping someone could help me out. The instructions are as follows:
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 as the user for a test score, store it in a reference parameter variable, and validate it. The function should be called by main once for each of the five test scores.
* void calcAverage() should calculate and display the average of the four highest scores. This function should be called just once by main, and should be passed the five test scores.
* int findLowest() should find and return the lowest of the five scores passed to it. It should be called by calcAverage, which uses the function to determin which of the five scores to drop.
Input validation: do not accept test scores lower than 0 or higher than 100.
My problem is as follows: after I get the scores in getScore() and pass them to calcAverage, they show up in e notation. I was wondering if my getScore() function is messed up, as I'm unsure about how to use the reference parameter. I've done the whole program myself - I just need help with that part to complete it. I would really appreciate any insight! (By the way, we are not at arrays yet so I would not know how to use them.)
Here is the code:
Code:
#include <iostream>
using namespace std;
void intro();
void getScore(double&);
void calcAverage(double, double, double, double, double);
int findLowest(double, double, double, double, double);
int main()
{
double score1,
score2,
score3,
score4,
score5;
intro();
getScore(score1);
getScore(score2);
getScore(score3);
getScore(score4);
getScore(score5);
calcAverage(score1, score2, score3, score4, score5);
system("pause");
return 0;
}
void intro()
{
cout << "This program will take five test scores from the user and calculate\n";
cout << "their average after dropping the lowest score.\n\n";
}
void getScore(double &score)
{
static double tScore;
tScore++;
cout << "Please enter a test score. ";
cin >> tScore;
while (tScore < 0 || tScore > 100)
{
cout << "Valid test scores range from 0 - 100.\n";
cout << "Please enter a test score. ";
cin >> tScore;
}
}
void calcAverage(double grd1, double grd2, double grd3, double grd4, double grd5)
{
double lowest;
double sum;
double average;
cout << grd1;
lowest = findLowest(grd1, grd2, grd3, grd4, grd5);
sum = (grd1 + grd2 + grd3 + grd4 + grd5);
average = (sum - lowest);
cout << "The average of the four highest test scores is "<<
average << ".\n\n";
}
int findLowest(double tScore1, double tScore2, double tScore3, double tScore4, double tScore5)
{
double lowest = tScore1;
if (lowest > tScore2)
lowest = tScore2;
if (lowest > tScore3)
lowest = tScore3;
if (lowest > tScore4)
lowest = tScore4;
if (lowest > tScore5)
lowest = tScore5;
}