Switch : Case statements

Discussion in 'Software' started by G_M_1, Jul 21, 2004.

  1. G_M_1

    G_M_1 Private E-2

    i've been fooling around with the following short program that i wrote.... trying to get the compiler to recognize the second integer that i enter, so that the number entered from the user will ouput its correct spelling...

    here is my code:
    #include <iostream>
    using namespace std;


    int main()
    {

    int number;



    for(int count=1; count<=10; count++) //program will run 10 times.
    {
    cout << "\nPlease enter one of the following integers (11, 12, 13, 14, 15) : ";

    cin >> number;

    switch(number)
    {
    case '11':
    cout <<"The number is ELEVEN.\n";
    break;
    case '12':
    cout <<"The number is TWELVE.\n";
    break;
    case '13':
    cout <<"The number is THIRTEEN.\n";
    break;
    case '14':
    cout <<"The number is FOURTEEN.\n";
    break;
    case '15':
    cout <<"The number is FIFTEEN.\n";
    break;
    default:
    cout << "The number is not supported.\n";
    }

    }


    return 0;

    }




    for some reason the only output i get is "The number is not supported". I tried switching number to type char instead of type int, and when i do so, it works. but only if i were to make the case a single digit, instead of a double digit.
    im very confused right now.... any help would be appreciated. thanks !
     
  2. snakefoot

    snakefoot Sergeant Major

    Instead of using case '11': (With single-quotes), then you should use case 11: without quotes.
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds