help with case switching or char

This is a discussion on help with case switching or char within the C++ Programming forums, part of the General Programming Boards category; can u use char with case switches or is there something you can do that is similar (i.e) Code: #include ...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    142

    help with case switching or char

    can u use char with case switches or is there something you can do that is similar (i.e)


    Code:
    #include <iostream>
    
    using namespace std;
    
    int main();
    
    {
    
    char a;
    
    cout "please choose a-c\n";
    cout "input :";
    
    cin.get();
    
    cin>> a;
    
    switch ( a ) 
    {
    
    case a:
    cout<<"a";
    cin.get();
    break;
    
    case b:
    cout<<"b";
    cin.get();
    break;
    
    case c:
    cout<<"c";
    cin.get();
    break;
    
    }
    
    }
    ok, i know this doesn't work cause i've tried it, but as an example i think you can see what i'm trying to do. if you have any input please, do tell!!
    WhAtHA hell Is GoInG ON

  2. #2
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    Code:
    #include <iostream>
    
    using namespace std;
    
    int main();
    
    {
    
    char a;
    
    cout "please choose a-c\n";
    cout "input :";
    
    cin.get();
    
    cin>> a;
    
    switch ( a ) 
    {
    
    case 'a':
    cout<<"a";
    cin.get();
    break;
    
    case 'b':
    cout<<"b";
    cin.get();
    break;
    
    case 'c':
    cout<<"c";
    cin.get();
    break;
    
    }
    
    }
    The little single quotes should do it for ya.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A Full Program to analyze.
    By sergioms in forum C Programming
    Replies: 2
    Last Post: 12-30-2008, 08:42 AM
  2. Format Precision & Scale
    By mattnewtoc in forum C Programming
    Replies: 1
    Last Post: 09-16-2008, 10:34 AM
  3. C problem with legacy code
    By andy_baptiste in forum C Programming
    Replies: 4
    Last Post: 05-19-2008, 06:14 AM
  4. char copy
    By variable in forum C Programming
    Replies: 8
    Last Post: 02-06-2005, 09:18 PM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21