Correct me if I'm wrong, would using
switch(avg / 10)
and having the average 79 using case 7 as giving a C round it off to so? I'm just a bit or so confused.
Sorry I wasn't sure what you were meaning pearlyman, but I think I do now. I'm not sure I want to try to make the code too complex. Maybe I should use be using double for what you said, I'd like to get more in-depth into what you said.
For the code itself, I think last week our professor was laughing at what our other professor was having us do, saying we would know very much afterwards how to use copy/paste
Well it's very handy, I know now for sure, and I think he was looking at us writing the assignment like this
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
|
#include <iostream>
#include <string>
using namespace std;
int main()
{
string name1, name2;
int gr1;
int gr2;
int gr3;
int gr4;
int gr5;
int avg;
char num; // Declared in order for switch statements to use numerals
cout << "Enter the first and last name of the student. \n" << endl;
cin >> name1 >> name2;
cout << "\nStudent:" << name1 << " " << name2 << endl;
cout << "\nEnter FIVE grades of STUDENT LAST NAME: " << name2 << endl;
cout << "\n1. \n\n";
cin >> gr1;
cout << "\n2. \n\n";
cin >> gr2;
cout << "\n3. \n\n";
cin >> gr3;
cout << "\n4. \n\n";
cin >> gr4;
cout << "\n5.\n\n";
cin >> gr5;
cout << "\n\n\n";
avg = (gr1 + gr2 + gr3 + gr4 + gr5) / 5;
cout << "Average of student: " << name1 << " " << name2 << " is " << avg;
switch (avg)
{
case 100: cout << " Grade is A";
break;
case 99: cout << " Grade is A";
break;
case 98: cout << " Grade is A";
break;
case 97: cout << " Grade is A";
break;
case 96: cout << " Grade is A";
break;
case 95: cout << " Grade is A";
break;
case 94: cout << " Grade is A";
break;
case 93: cout << " Grade is A-";
break;
case 92: cout << " Grade is A-";
break;
case 91: cout << " Grade is A-";
break;
case 90: cout << " Grade is A-";
break;
case 89: cout << " Grade is B+";
break;
case 88: cout << " Grade is B+";
break;
case 87: cout << " Grade is B+";
break;
case 86: cout << " Grade is B";
break;
case 85: cout << " Grade is B";
break;
case 84: cout << " Grade is B";
break;
case 83: cout << " Grade is B";
break;
case 82: cout << " Grade is B";
break;
case 81: cout << " Grade is B-";
break;
case 80: cout << " Grade is B-";
break;
case 79: cout << " Grade is C+";
break;
case 78: cout << " Grade is C+";
break;
case 77: cout << " Grade is C+";
break;
case 76: cout << " Grade is C";
break;
case 75: cout << " Grade is C";
break;
case 74: cout << " Grade is C";
break;
case 73: cout << " Grade is C";
break;
case 72: cout << " Grade is C-";
break;
case 71: cout << " Grade is C-";
break;
case 70: cout << " Grade is C-";
break;
case 69: cout << " Grade is D+";
break;
case 68: cout << " Grade is D+";
break;
case 67: cout << " Grade is D+";
break;
case 66: cout << " Grade is D";
break;
case 65: cout << " Grade is D";
break;
case 64: cout << " Grade is D";
break;
case 63: cout << " Grade is D";
break;
case 62: cout << " Grade is D-";
break;
case 61: cout << " Grade is D-";
break;
case 60: cout << " Grade is D+-";
break;
case 59: cout << " Grade is F";
break;
default:
cout << "\n Grade is invalid ";
}
cout << "\n" << endl;
return 0;
}
|
I'm going to see how to implement what LB said, it should be a simple couple of lines if I'm imagining his solution correctly although I'm not sure how giving specific letter grades is going to work with it. I wonder how decimaled grades is going to work.