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
|
/* A program that prompts a user for their grades, finds the average and prints out a letter grade.
The program calls a function called GetGrades that will read in grades from the keyboard, the number of grades should also be input by the user.
GetGrades will find the sum of those grades and pass the sum and number of grades to another function called FindAverage.
FindAverage will find the average of the grades and return this average to GetGrades.
GetGrades will return this average to main.
The main function will then determine the letter grade of that average based on a 10-point scale and print out this grade.
90–100 A
80–89 B
70–79 C
60–69 D
0–59 F
Sample Runs:
Run1 – 30, 50, 90, 100.
Run2 – 85, 89, 90, 95, 78, 99.
Run3 – 85, 95.
*/
#include <iostream>
using namespace std;
float GetGrades(float);
float FindAverage(float, float);
int main()
{
float returnVar;
float average;
GetGrades(average);
//average=GetGrades(returnVar);
cout << average << endl;
return 0;
}
float GetGrades(float average)
{
float gradeSum;
float gradeNum;
float studentGrade;
cout << "How many grades do you have to input?" << endl;
cin >> gradeNum;
for(int num=1; num<=gradeNum; num++)
{
cout << "Enter a student grade" << endl;
cin >> studentGrade;
// add the positive number to sum everytime the loop cycles.
gradeSum += studentGrade;
}
FindAverage(gradeSum, gradeNum);
cout << FindAverage(gradeSum, gradeNum);
average=FindAverage(gradeSum, gradeNum);
return (average);
}
float FindAverage(float gradeSum, float gradeNum)
{
return (gradeSum/gradeNum);
}
|