Hello! I am trying to make a simple function that outputs a grade for a person based on the amount of points they received for a given test/assignment (this means the user needs to input the amount of points possible as well). These assignment point values are added to an accumulator variable and when a negative number is entered the program outputs the user's overall grade (whether it be an A, B, C, D, or F) along with the percentage value they received. The problem I am having is that these two errors are reported when I try to build it:
Compiling: C:\Users\Owner\Desktop\C++ Files\Grading System.cpp
C:\Users\Owner\Desktop\C++ Files\Grading System.cpp: In function 'void displayLetterGrade(int, int)':
C:\Users\Owner\Desktop\C++ Files\Grading System.cpp:112: error: expected ';' before '{' token
C:\Users\Owner\Desktop\C++ Files\Grading System.cpp: In function 'void displayOverallLetterGrade(int, int)':
C:\Users\Owner\Desktop\C++ Files\Grading System.cpp:170: error: expected ';' before '{' token
Process terminated with status 1 (0 minutes, 1 seconds)
2 errors, 0 warnings.
What is wrong with my code?
I am also wondering if there is a more elegant/less spacious way to do what I did in the displayLetterGrade and displayOverallLetterGrade functions.
Any help would be much appreciated!
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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
|
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
void displayLetterGrade(int ScoreAchieved, int TotalScore);
void displayOverallLetterGrade(int nStudentPoints, int nTotalPoints);
int main()
{
cout << "This program assigns gives you a grade "
<< "based on the amount of points your class\n"
<< "has been administered divided by the amount "
<< "of points you have been able to get. It also\n"
<< "gives you a grade the same way on an individual "
<< "assignment.\n"
<< "when you would like to view your overall grade "
<< "enter a negative number.";
int nScoreAccumulator = 0;
int nScoreOverallAccumulator = 0;
for(;;)
{
cout << "Please enter your grade score on a test/assignment:";
int nScore = 0;
cin >> nScore;
if (nScore < 0)
{
break;
}
cout << "\nNow please enter the amount of points possible for the test/assignment:";
int nScoreOverall = 0;
cin >> nScoreOverall;
if(nScoreOverall < 0)
{
break;
}
displayLetterGrade(nScore,nScoreOverall);
nScoreAccumulator += nScore;
nScoreOverallAccumulator += nScoreOverall;
}
displayOverallLetterGrade(nScoreAccumulator,nScoreOverallAccumulator);
system("PAUSE");
return 0;
}
void displayLetterGrade(int ScoreAchieved, int TotalScore)
{
double dPercentageGrade = (ScoreAchieved / TotalScore) * 100;
if (100 > dPercentageGrade && dPercentageGrade > 97)
{
cout << "You got an A+ on this asssignment.";
}
else if(97 > dPercentageGrade && dPercentageGrade > 93)
{
cout << "You got an A on this asssignment.";
}
else if(93 > dPercentageGrade && dPercentageGrade > 90)
{
cout << "You got an A- on this asssignment.";
}
else if(90 > dPercentageGrade && dPercentageGrade > 87)
{
cout << "You got a B+ on this asssignment.";
}
else if(87 > dPercentageGrade && dPercentageGrade > 83)
{
cout << "You got a B on this asssignment.";
}
else if(83 > dPercentageGrade && dPercentageGrade > 80)
{
cout << "You got a B- on this asssignment.";
}
else if(80 > dPercentageGrade && dPercentageGrade > 77)
{
cout << "You got a C+ on this asssignment.";
}
else if(77 > dPercentageGrade && dPercentageGrade > 73)
{
cout << "You got a C on this asssignment.";
}
else if(73 > dPercentageGrade && dPercentageGrade > 70)
{
cout << "You got a C- on this asssignment.";
}
else if(70 > dPercentageGrade && dPercentageGrade > 67)
{
cout << "You got a D+ on this asssignment.";
}
else if(67 > dPercentageGrade && dPercentageGrade > 63)
{
cout << "You got a D on this asssignment.";
}
else if(63 > dPercentageGrade && dPercentageGrade > 60)
{
cout << "You got a D- on this asssignment.";
}
else(60 > dPercentageGrade && dPercentageGrade > 0)
{
cout << "You got an F on this asssignment.";
}
return;
}
void displayOverallLetterGrade(int nStudentPoints,int nTotalPoints)
{
double nFinalGrade = (nStudentPoints / nTotalPoints) * 100;
if (100 > nFinalGrade && nFinalGrade > 97)
{
cout << "You got an A+ in this class with a percentage of " << nFinalGrade << "%" << endl;
}
else if(97 > nFinalGrade && nFinalGrade > 93)
{
cout << "You got an A in this class with a percentage of " << nFinalGrade << "%" << endl;
}
else if(93 > nFinalGrade && nFinalGrade > 90)
{
cout << "You got an A- in this class with a percentage of " << nFinalGrade << "%" << endl;
}
else if(90 > nFinalGrade && nFinalGrade > 87)
{
cout << "You got a B+ in this class with a percentage of " << nFinalGrade << "%" << endl;
}
else if(87 > nFinalGrade && nFinalGrade > 83)
{
cout << "You got a B in this class with a percentage of " << nFinalGrade << "%" << endl;
}
else if(83 > nFinalGrade && nFinalGrade > 80)
{
cout << "You got a B- in this class with a percentage of " << nFinalGrade << "%" << endl;
}
else if(80 > nFinalGrade && nFinalGrade > 77)
{
cout << "You got a C+ in this class with a percentage of " << nFinalGrade << "%" << endl;
}
else if(77 > nFinalGrade && nFinalGrade > 73)
{
cout << "You got a C in this class with a percentage of " << nFinalGrade << "%" << endl;
}
else if(73 > nFinalGrade && nFinalGrade > 70)
{
cout << "You got a C- in this class with a percentage of " << nFinalGrade << "%" << endl;
}
else if(70 > nFinalGrade && nFinalGrade > 67)
{
cout << "You got a D+ in this class with a percentage of " << nFinalGrade << "%" << endl;
}
else if(67 > nFinalGrade && nFinalGrade > 63)
{
cout << "You got a D in this class with a percentage of " << nFinalGrade << "%" << endl;
}
else if(63 > nFinalGrade && nFinalGrade > 60)
{
cout << "You got a D- in this class with a percentage of " << nFinalGrade << "%" << endl;
}
else(60 > nFinalGrade && nFinalGrade > 0)
{
cout << "You got an F in this class with a percentage of " << nFinalGrade << "%" << endl;
}
return;
}
|