#include <iostream>
using namespace std;
//------------------------------------Function Declarations-----------------------------------------
int humanSetData();
int humanSetUnit();
int alienSetData();
int alienSetUnit();
//------------------------------------------Classes-------------------------------------------------
/////////////////////////////////////////////HUMANS/////////////////////////////////////////////////
struct Humans
{
public:
char * userName;
int health;
Humans()
{}
}human1;
/////////////////////////////////////////////ALIENS/////////////////////////////////////////////////
struct Aliens
{
public:
char * userName;
int health;
Aliens()
{}
}alien1;
////////////////////////////////////////GLOBAL VARIABLES////////////////////////////////////////////
//--------------------------------------------MAIN--------------------------------------------------
int main()
{
//Any temporary variables
int choice;
//Choose your race
cout << "\"Come on!\" You''re fellow beings are in a frenzy! Help them survive!\n\n";
cout << "Choose you''re race now; 1 - Humans OR 2 - Aliens: ";
cin >> choice;
switch(choice)
{
case ''1'':
{
humanSetData();
break;
}
case ''2'':
{
alienSetData();
break;
}//compiler doesn''t care if there''s a ; or not!
default:break;
}
return(0);
}
int humanSetData()
{
char temp_name[30];
cout << "\n\n\"Alrighty then! Let''s get youse registered!\nName: ";
cin >> temp_name[30];
human1.userName = temp_name;
cout << "\"All right, welcome aboard you newbie!. Let''s get down to business quick like!";
cout << " You know what''s happening out there. So get out and help us win this battle!\"";
return(0);
}
int alienSetData()
{
return(0);
}
Game Acts UP!
Why doesn''t the switch statement work?
Also, the comipler doesn''t care if there''s a semicolon after the switch statement. (Commented) Why?
----------
Take it to the Xtreme!
----------
Wachar's Eternity <-<-<-<-<- Me own site!
When you do:
Don''t use brackets.
-AJ
C:\DOS
C:\DOS\RUN
RUN\DOS\RUN
-Comic Book Store Guy''s t-shirt that I saw on the Simpsons, although it didn''t actually come from the Simpsons.
http://vdsoft.netfirms.com/home.html
case ''1'': { humanSetData(); break; }case ''2'': } alienSetData(); break; }
Don''t use brackets.
-AJ
C:\DOS
C:\DOS\RUN
RUN\DOS\RUN
-Comic Book Store Guy''s t-shirt that I saw on the Simpsons, although it didn''t actually come from the Simpsons.
http://vdsoft.netfirms.com/home.html
C:DOSC:DOSRUNRUNDOSRUN-Comic Book Store Guy's t-shirt that I saw on the Simpsons, although it didn't actually come from the Simpsons.http://vdsoft.netfirms.com/home.html
choice is an int, in your switch statement you''re comparing it to the characters ''1'' and ''2'', which are much different from the numbers 1 and 2. Using extra braces in a switch statement is fine, you don''t need them but all it does is create a new scope, allowing variables to be initialized and then destroyed when it hits the } (which can actually be useful in a few cases). But to fix your problem, either make choice a char or compare 1 and 2 rather than ''1'' and ''2''.
- f l u c k y p o o
- the geek inside
- f l u c k y p o o
- the geek inside
- f l u c k y p o o
It''s quite possible that I''m mistaken, but I don''t think there''s any harm in using brackets inside switch statements. Depending on what you''re doing inside the switch, they''re required sometimes.
But ya, if your code compiles properly, (i noticed your "''s weren''t matched up properly sometimes.. but that could be just a typo) the reason your switch statement doesn''t work is because of the single-quote marks you''re using in your case statements..
if choice was a ''char'' variable, then saying:
case ''1'':
would be fine.. but seeing how you''ve declared choice as an int.. maybe you should try changing your case statment to something like:
case 1:
pretty much the same as you had done before, except without the single quote marks.
Hope this helps
Ern
But ya, if your code compiles properly, (i noticed your "''s weren''t matched up properly sometimes.. but that could be just a typo) the reason your switch statement doesn''t work is because of the single-quote marks you''re using in your case statements..
if choice was a ''char'' variable, then saying:
case ''1'':
would be fine.. but seeing how you''ve declared choice as an int.. maybe you should try changing your case statment to something like:
case 1:
pretty much the same as you had done before, except without the single quote marks.
Hope this helps
Ern
groovy,ern
quote: Original post by redneckCoder
Don''t use brackets.
Braces are necessary if you declare variables within that scope, as the jumps for other cases cause that variable initialization to be skipped - a compile-time error.
[ GDNet Start Here | GDNet Search Tool | GDNet FAQ ]
[ MS RTFM [MSDN] | SGI STL Docs | Boost ]
[ Google! | Asking Smart Questions | Jargon File ]
Thanks to Kylotan for the idea!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement