Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,262 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,504 people online right now. Registration is fast and FREE... Join Now!




Switch Statement

 
Reply to this topicStart new topic

Switch Statement, error

aznballerlee
16 Oct, 2006 - 04:54 PM
Post #1

D.I.C Head
**

Joined: 14 Oct, 2006
Posts: 61


My Contributions
CODE


#include <iostream>
using namespace std;

int main()
{
    int lec;
    
            
cout    <<    "What is the lecture number?" << endl
            <<    "0 - Unassigned" << endl
            <<    "1 - Smelly" << endl
            <<    "2 - Smelly" << endl
            <<    "3 - Roar << endl

    cout << "Enter an option: ";
    cin >> option;
    
switch(lec)
{

case 0:
cout << “Unassigned” << endl;
break;

case 1:
cout << “Smelly” << endl;
break;


case 2:
cout << “Smelly” << endl;
break;

case 3:
cout << “Roar” << endl;
break;

default:
cout << "Who?" << endl;
    
}

return 0;
}




____

What is wrong with my switch statement?
Why won't it execute?
User is offlineProfile CardPM
+Quote Post

Mrafcho001
RE: Switch Statement
16 Oct, 2006 - 05:03 PM
Post #2

D.I.C Addict
Group Icon

Joined: 1 Nov, 2005
Posts: 753



Thanked: 5 times
Dream Kudos: 120
My Contributions
wow dude use your logic...

you are taking the input into variable option (which by the way is never declared, so you should get a compilation error right there...)

But then you switch lec, which has been declared but never initialized.
User is offlineProfile CardPM
+Quote Post

NyeNye
RE: Switch Statement
16 Oct, 2006 - 05:09 PM
Post #3

D.I.C Head
**

Joined: 24 Sep, 2006
Posts: 248


My Contributions
in short you never used "lec",

be careful for declaration and usage of it..

analyze...
User is offlineProfile CardPM
+Quote Post

quim
RE: Switch Statement
16 Oct, 2006 - 05:10 PM
Post #4

D.I.C Head
Group Icon

Joined: 11 Dec, 2005
Posts: 145



Thanked: 2 times
Dream Kudos: 350
My Contributions
There is nothing wrong with your switch():

what i see is a ; after << "3 - Roar" << endl

cin >> option; you want to put lec as you declared intead of option

This post has been edited by quim: 16 Oct, 2006 - 05:16 PM
User is offlineProfile CardPM
+Quote Post

aznballerlee
RE: Switch Statement
16 Oct, 2006 - 05:15 PM
Post #5

D.I.C Head
**

Joined: 14 Oct, 2006
Posts: 61


My Contributions
My mistake for the previous errors.

I have updated my program to this:
CODE


#include <iostream>
using namespace std;

int main()
{
    int lec;
    
            
cout    <<    "What is the lecture number?" << endl
            <<    "0 - Unassigned" << endl
            <<    "1 - Smelly" << endl
            <<    "2 - Smelly" << endl
            <<    "3 - Roar" << endl

            cout << "Enter a lecture number: ";
            cin >> lec;
    
switch(lec)
{

case 0:
cout << “Unassigned” << endl;
break;

case 1:
cout << “Smelly” << endl;
break;


case 2:
cout << “Smelly” << endl;
break;

case 3:
cout << “Roar” << endl;
break;

default:
cout << "Who?" << endl;
    }

return 0;
}



The errors I receive are:
QUOTE

error C2146: syntax error : missing ';' before identifier 'cout'
error C2065: '“Unassigned”' : undeclared identifier
error C2065: '“Smelly”' : undeclared identifier
error C2065: '“Roar”' : undeclared identifier

What's wrong this time?
User is offlineProfile CardPM
+Quote Post

NyeNye
RE: Switch Statement
16 Oct, 2006 - 05:22 PM
Post #6

D.I.C Head
**

Joined: 24 Sep, 2006
Posts: 248


My Contributions
terminate your first cout....



analyze........
User is offlineProfile CardPM
+Quote Post

aznballerlee
RE: Switch Statement
16 Oct, 2006 - 05:32 PM
Post #7

D.I.C Head
**

Joined: 14 Oct, 2006
Posts: 61


My Contributions
I still get the same results.

QUOTE

error C2065: '“Unassigned”' : undeclared identifier
error C2065: '“Smelly”' : undeclared identifier
error C2065: '“Roar”' : undeclared identifier

User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Switch Statement
16 Oct, 2006 - 05:34 PM
Post #8

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,230



Thanked: 40 times
Dream Kudos: 25
My Contributions
In addition to your first cout statement requring a semi colon to terminate, you seem to be getting errors for your cout usage in the case statements...what are you using for quotes? They appear different then the usual double quotes.
User is offlineProfile CardPM
+Quote Post

aznballerlee
RE: Switch Statement
16 Oct, 2006 - 05:46 PM
Post #9

D.I.C Head
**

Joined: 14 Oct, 2006
Posts: 61


My Contributions
Thanks! Problem is now solved.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/4/08 07:13PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month