well im trying to make a program that when a person enters a letter such as A,a,B,b,C,c,D,d,F,f it will show up on the console saying your grade. i am stuck and don't know what to do. although i got this far.
Code:
//adds the iostream library to the program
#include <iostream>
//adds the iomanip library to the program
#include <iomanip>
//adds the math library to the program
#include <cmath>
// this one is for the system library =)
#include <cstdlib>
//informs the compiler you are using the standard library set
using namespace std;
int main ()
{
int LetterGrade;
cout << "Mini Program 5.2\n";
cout << "Enter the letter grade: ";
cin >> LetterGrade;
cout << endl;
switch(LetterGrade)
{
if (LetterGrade = 'A' || 'a')
case 'A' : cout << "a perfect score. Excellent." << endl; break;
else if (LetterGrade = 'B' || 'b')
case 'B' : cout << "well above average. Keep up the good work. " << endl;break;
else if (LetterGrade = 'C' || 'c')
case 'C' : cout << "average: keep trying you will get there." << endl;break;
else if (LetterGrade = 'D' || 'd')
case 'D' : cout << "below average: seems you need some extra help." << endl;break;
else if (LetterGrade = 'F' || 'f')
case 'F' : cout << "not passing: spend some more time asking questions and make sure you understand the material ahead of time." << endl;break;
else
default : cout << "LETTER DOES NOT EXIST" << endl; break;
}
system("pause");
return 0;
}
ok so i fixed it a bit that way it compiles then when i type to enter A it says the letter does not exist even though i declared it in the case.
Code:
//adds the iostream library to the program
#include <iostream>
//adds the iomanip library to the program
#include <iomanip>
//adds the math library to the program
#include <cmath>
// this one is for the system library =)
#include <cstdlib>
//informs the compiler you are using the standard library set
using namespace std;
int main ()
{
int LetterGrade;
cout << "Mini Program 5.2\n";
cout << "Enter the letter grade: ";
cin >> LetterGrade;
cout << endl;
switch(LetterGrade)
{
case 'A' : cout << "a perfect score. Excellent." << endl; break;
case 'B' : cout << "well above average. Keep up the good work. " << endl;break;
case 'C' : cout << "average: keep trying you will get there." << endl;break;
case 'D' : cout << "below average: seems you need some extra help." << endl;break;
case 'F' : cout << "not passing: spend some more time asking questions and make sure you understand the material ahead of time." << endl;break;
default : cout << "LETTER DOES NOT EXIST" << endl; break;
}
system("pause");
return 0;
}