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
|
#include <iostream>
using namespace std;
void gradesInput(int &test1, int &test2, int &test3) {
cout << "You will be prompted to enter your three test scores" << endl;
cout << "Please make sure your number is between 0 and 100." << endl;
cout << "Please enter your first test score: ";
cin >> test1;
cout << "\nPlease enter your second test score: ";
cin >> test2;
cout << "\nPlease enter your third test score: ";
cin >> test3;
}
double average3Scores(int test1, int test2, int test3) {
double avg1 = ((test1 + test2 + test3) / 3.0); // calculating the average without rounding
avg1 = (int)(avg1 + 0.5); //this rounds the test average
return avg1;
}
double average2Scores(int test2, int test3) {
double avg2 = ((test2 + test3) / 2.0);
avg2 = (int)(avg2 + 0.5);
return avg2;
}
char toLetterGrade(double avg1, double avg2, int test3) {
if (avg1 >= 90)
return 'A';
else if (avg1 >= 70)
if (test3 >= 90)
return 'A';
else
return 'B';
else if (avg1 >= 50)
if (avg2 >= 70)
return 'C';
else
return 'D';
else
return 'F';
}
void displayGrade(double avg, char lGrade) {
cout << "Your average is: " << avg << endl;
cout << "Your grade is: " << lGrade << endl;
}
int main() {
int test1, test2, test3;
double avg1, avg2;
char lGrade;
gradesInput(test1, test2, test3);
average3Scores(test1, test2, test3);
average2Scores(test2, test3);
toLetterGrade(avg1, avg2, test3);
displayGrade(avg1, lGrade);
system("pause");
return 0;
}
|