Trying to get the program to read Lowercase letters as well

Hello Fellow programmers i am new at this and i'm having trouble with this program. I want it to read lowercase and uppercase letters but for some odd reason it is not working.



#include <iostream>
using namespace std;

char getGrade()
{

char grade = 'Q'; //the default value
while (true)
{

cout << "what is your grade ? [ A,B,C,D,F, or Q to qit]:";
cin >> grade;
cin.ignore(1000,10);

if (grade == 'A' || grade == 'B' ||grade=='C' ) break;
if (grade == 'D' || grade == 'F' ) break;
if (grade == 'Q') break;

cout << grade << "is not vaild grade. Try again.." <<endl;

}//end while
return grade;
}//getGrade


int main ()
{
char grade;
while (true)
{
grade = getGrade();
if (grade == 'Q' || ) break;
if (grade == 'A' || grade == 'B' || grade == 'C' )
cout << "You pass" << endl;
}//while


cout << "Thanks for checking your grade!" << endl;
return 0;

}//main
Last edited on
How can the term grade == 'A' and grade == 'a' ever be evaluated to true if 'A' does not equal 'a'?
if (grade == 'Q' || )

So, if grade is Q OR .... nothing? What's going on there?
The simple way of doing it would be to just duplicate the code you used to check for the uppercase letters and change it to lowercase, like this:

1
2
3
if(grade == 'Q' || grade == 'q') break;
if(grade == 'A' || grade == 'a' || grade == 'B' || grade == 'b' || grade == 'C' || grade == 'c')
cout << "You pass" << endl;


Do the same when you read in the getGrade() function too.

It's not elegant, but it should work.
A simpler way would be converting the input to lower case and evaluating that, rather than checking for both cases.
iHutch is right .
You can use this
grade = toupper (grade) ;

so if grade was a lowercase char it will become an uppercase . Anyway for this you will have to include <cctype> or <ctype.h>

You can learn more about this function here : http://www.cplusplus.com/reference/clibrary/cctype/toupper/
Last edited on
Just adding an important point:

Use the 'code' option(from format) while posting, so that the code becomes more legible to read
Topic archived. No new replies allowed.