0

The lab focuses on testing characters. I am supposed to enter a character and it will read if it is a capital letter it lowercase letter or another type. My if statements are correct. My statements which prompt for and read what I put in are okay, too. The problem is that when I enter q or Q which should make the program end, the program still reads the q or Q that I entered. Shouldn't the program end and not read those letters once I enter it?

 int main()
    {
        char input = ' ';

        //set up loop such that all tasks below is done as long as input
        // is not a q or a Q (that is, quit)
        while (toupper(input) != 'Q' || tolower(input) != 'q') 
        {
            cout << "Enter any character: ";
            cin.get(input);
            cin.ignore(); 
            cout << "The character you entered is: " << input << endl;

            if (isalpha(input))
                cout << "That's an alphabetic character.\n";
            if (isdigit(input))
                cout << "That's a numeric digit.\n";
            if (islower(input))
                cout << "The letter you entered is lowercase.\n";
            if (isupper(input))
                cout << "The letter you entered is uppercase.\n";
            if (isspace(input))
                cout << "That's a whitespace character.\n";

            //add code to test for alphanumeric 
            if (isalnum(input))
                cout << "The character you entered is alphanumeric.\n"; 

            //add code for a punctuation
            if (ispunct(input))
                cout << "The character you entered is a punctuation.\n";
        } 

        system("PAUSE"); 
        return 0;
    }
Mary
  • 211
  • 1
  • 8
  • 18
  • Not the problem here, but http://stackoverflow.com/questions/21805674/do-i-need-to-cast-to-unsigned-char-before-calling-toupper – Baum mit Augen Mar 19 '15 at 00:45
  • Your problem is `system("PAUSE")`, after you exit the while loop with 'q' or 'Q' the program is still sitting there waiting for input/output. – DigitalNinja Mar 19 '15 at 00:46
  • 1
    You don't need to check for the lower case `q`. The first expression will convert a lower case `q` to upper case 'Q` before the comparison. – Thomas Matthews Mar 19 '15 at 01:10

1 Answers1

1

Remove system("PAUSE"); and try it again.

After you exit the while loop with 'q' or 'Q' the program/console is still sitting there waiting for input/output.

DigitalNinja
  • 1,078
  • 9
  • 17
  • I removed the system("PAUSE") and ran the program again. It runs and exits once I enter the q/Q but it looks like it still reads it but there's no pause anymore. – Mary Mar 19 '15 at 00:56