Test and Average Program Using Strings

Write a program that asks the user to enter five test scores. The program should display a letter grade for each score and the average test score. Design the following functions in the program:
calcAverage- this function should accept five test scores as arguments and return the average of the scores.

determineGrade—This function should accept a test score as an argument and return a letter grade for the score (as a String), based on the following grading scale:
90-100 A
80-89 B
70-79 C
60-69 D
Below 60 F

This is what I have so far and I need help with the rest..

#include<iostream>
#include<iomanip>

using namespace std;
float calcAverage(score1, score2, score3, score4, score5, average);
float determineGrade();

int main()
{
double score1, score2, score3, score4, score5, average;

cout << "Enter score 1: ";
cin >> score1;
cout << "Enter score 2: ";
cin >> score2;
cout << "Enter score 3: ";
cin >> score3;
cout << "Enter score 4: ";
cin >> score4;
cout << "Enter score 5: ";
cin >> score5;

average = (score1 + score2 + score3 + score4 + score5) / 5;

cout << setprecision(1) << fixed;
cout << "The average score is: " << average << endl << endl;

system("pause");

return 0;
}

//Function to calculate Average
float calcAverage(score1, score2, score3, score4, score5, average);
calcAverage():
1
2
3
4
5
//Function to calculate Average
float calcAverage(double score1, double score2, double score3, double score4, double score5) // Note: Change the prototype above too.
{
  return (score1 + score2 + score3 + score4 + score5) / 5;
}
1
2
3
4
5
//Function to calculate Average
float calcAverage(float score1, float score2, float score3, float score4, float score5)
{
        return (score1 + score2 + score3 + score4 + score5) / 5;
}

I would recommend to keep the scores and average to one type. I've chosen float as it's precise enough for what you need to do.
closed account (zNASE3v7)
I recommend keeping everything as either double or float, one or the other...that's good conventional programming according to what I've been told.
You already have all of your scores declared as doubles in main(), and probably it is more common to use doubles anyway, unless you start using the long decimals, more for the Engineering, Scientific, and Space etc...that's according to my Professor.
Secondly you are also using only a fixed precision of 1 decimal place. so it is a rounded number to that which is like 99.18 == 99.0, or 50.007 == 50.0, etc...
If you are using fixed of greater than 2 decimal places that is probably the most common form for using floats...Just fyi... It might give you a bit higher grade all

Good luck w your programming
Topic archived. No new replies allowed.