how char read two digit integer

solved
Last edited on
Hi,

Change the type of the variable to unsigned short, change all the cases in the switch to reflect that.

Hope all goes well.
> i guess char cannot read 2 digit integer, what should i do?

Use int

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
int main()
{
    // char b;
    int amendment_number ; // ****

    do{
        try{
            cout << "Which amendment?";
            cin >> amendment_number;

            // if( b < '1' or b > '8')
            if( amendment_number < 1 or amendment_number > 27 ) // ****
            {
                error("That is not a valid input. Please enter a number betweet 1 and 27.");
            }

            switch(amendment_number)
            {
                // case'1':
                case 1 : // ****
                    cout << "Amendment 1: Freedom of speech, the press, to form militias, of religion, and of the right to assemble." << endl;
                break;

                // case'2':
                case 2 : // ****
                    cout << "Amendment 2: The right to bear arms and form militias." << endl;
                break;

                // etc. 
thank you for helping me guys
Please don't delete your original post, it is bad form here, and it may be helpful to others.

Regards
Topic archived. No new replies allowed.