Sentinel Value to determine Type of Character

Hello everyone. I have the following lab instructions:

Write a program that will prompt a user to enter a single character, the prompting will continue till a sentinel value is entered. For each character entered perform the following tests and print out a relevant message if the character passes the test. Print out a default message if the character does not pass any of the tests.
Tests that should be in program: Punctuation, Upper Case, Digit, White Space.
Sample Run: “A”, “a”, “7”, <tab>, “?”, “$”

So far I have the following code done. The problem is that when I run the program, the first character is correctly identified. However, every character afterwards is defined as a whitespace character.
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
#include <iostream>
#include <cctype>
#include <cstring>

using namespace std;

int main()


{
    char input;
    char response;
    do
    {
    cout << "Enter any character: " << endl;
    cin.get(input);
    cin.ignore();
    cout << input << endl;
    if(ispunct( input))
        cout << "That's a punctuation character ";
    if(isdigit( input))
        cout << "Thats a numeric digit ";
    if(isupper( input))
        cout << "The letter is uppercase ";
    if(isspace( input))
        cout << "That's a whitespace character ";
    if(islower( input))
        cout << "That's a lowercase letter";
        do
        {
        cout << "Enter another? (Y or N) ";
        cin >> response;
        response = toupper(response);
        }while (response != 'Y' && response != 'N');
    } while (response == 'Y' );
    return 0;
}
Add a cin.ignore(); after line 32. You need to remove the newline from the stream after the input extraction operation. In fact, you can put it there and get rid of the one on 17 if you desired. The cin >> response; will skip leading whitespace.
Thank you so much! That did the trick. I can't believe I forgot to put that.
Topic archived. No new replies allowed.