switch statement issues...(undeclared identifiers)

This is a discussion on switch statement issues...(undeclared identifiers) within the C++ Programming forums, part of the General Programming Boards category; I am trying to work this switch statement into my future reference program. Code: char playSong; std::cout << "Which is ...

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    18

    Question switch statement issues...(undeclared identifiers)

    I am trying to work this switch statement into my future reference program.

    Code:
    char playSong;
        std::cout << "Which is best? La, Da, or This..." << endl;
        std::cin >> playSong;
        switch (playSong){
            case L:
                std::cout << "Lalalalala" << endl;
                break;
            case D:
                std::cout << "Da da da" << endl;
                break;
            case T:
                std::cout << "This love has taken it's toll..." << endl;
                break;
            default:
                std::cout << "Your done." << endl;
                break;
        }
    The error is saying that L, D, and T are undeclared identifiers...what do I do to solve that?

  2. #2
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540
    case 'L':
    std::cout << "Lalalalala" << endl;
    break;
    case 'D':
    std::cout << "Da da da" << endl;
    break;
    case 'T':
    std::cout << "This love has taken it's toll..." << endl;
    break;
    default:
    std::cout << "Your done." << endl;
    break;
    You need to add ' ' around your letters, otherwise the compiler thinks they are variables.
    i don't think most standard compilers support programmers with more than 4 red boxes - Misplaced

    It is my sacred duity to stand in the path of the flood of ignorance and blatant stupidity... - quzah

    Such pointless tricks ceased to be interesting or useful when we came down from the trees and started using higher level languages. - Salem

  3. #3
    Registered User
    Join Date
    Feb 2005
    Posts
    18
    Thanks, andy.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting the switch statement to work.
    By mtymightymike in forum C Programming
    Replies: 7
    Last Post: 10-15-2008, 06:32 PM
  2. Stack operations from switch statement elements
    By mlsrar in forum C Programming
    Replies: 15
    Last Post: 10-02-2008, 01:12 PM
  3. switch statement
    By guillermoh in forum C Programming
    Replies: 5
    Last Post: 03-10-2008, 02:17 PM
  4. Replies: 17
    Last Post: 11-11-2007, 12:30 PM
  5. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 05:45 AM

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