problem... help please

Discussion in 'C++' started by noob2007, Apr 12, 2007.

  1. noob2007

    noob2007 New Member

    Joined:
    Apr 12, 2007
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    the code below works fine but there is a few problems
    it displays:
    please enter the character you want:
    The character you have entered is translated into a '' but you also have decided to exit the program

    THis is not suppose 2 happen. it SUPPOSe to ask you to enter the space character then it displays teh converted character. then if teh user enter ' . 'then it will display the message and you will exit

    im new to C++
    this is my code:

    Code:
    case 2: //character 'space' condition 
    cout << "\n Note: Enter '.'(i.e. dot, full stop or decimal point) to exit\n\n"; 
    
    while (ch != '.')
    
    { 
    cout << "Please enter the character you want: ";
    ch = cin.get();
    
    switch (ch) 
    { 
    case ' ':
    cout << "\nThe character you have entered is translated into a '_' (underscore)"<< endl << "\n";
    break;
    
    default:
    cout << "\nThe character you have entered is translated into a " << "'" << ch << "'" << "but you also have decided";
    cout << " to exit the program...\n\n"; 
    }
    
    }
    break;
     
    Last edited by a moderator: Apr 12, 2007
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    You have posted it as an Article under the Article / Source code section. I have moved it to the Queries and Discussion forum.

    Also try reading [thread=168]Before you make a query[/thread] thread and specifically have a better topic so it helps all of us including the person searching
     
  3. noob2007

    noob2007 New Member

    Joined:
    Apr 12, 2007
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
  4. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    http://www.daweidesigns.com
    The ENTER key is not a space, but it is a character, therefore the default path in the switch is taken and the program exits.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice