ok im trying to make a video game for school medterm.. problem is it runs the females and male selection when it shouldnt... is this a syntax error or code error.. what can i do to fix it??

#include <iostream.h>
#include <iomanip.h>
#include <cstdlib>
main()
{
char gender;
char option;
char race;
int hp;
cout << "Please choose your gender(M/F). ";
cin >> gender;
switch(gender)
       {
       case 'M':
       cout << "You have chosen a male character. \n";
            cout << "Please choose your class.(Mage,Fighter,Archer.[M,F,A]) ";
            cin >> race; 
            switch(race)
             { //start of male race switch
              case 'M':
              cout << "You have chosen the Mage. ";
              hp = 75;
              break;
       
               case 'F':
               cout << "You have chosen the Fighter. ";
               hp = 120;
               break;
               
               case 'A':
               cout << "You have chosen the Archer. ";   
               hp = 100;
               break;
             
               }//end of male race switch
          break;    
       
       case 'F':
       cout << "You have chosen a female character.\n ";
            cout << "Please choose your class.(Mage,Fighter,Archer.[M,F,A]) ";
            cin >> race;   
            switch(race)
            {//start of female race switch
            case 'M':
            cout << "You have chosen the Mage. ";
            hp = 75;
            break;
       
            case 'F':
            cout << "You have chosen the Fighter. ";
            hp = 120;
            break;
           
            case 'A':
            cout << "You have chosen the Archer. "; 
            hp = 100;   
            break;
            
            }//end of F race switch
break;
            }//end of Gender
                    
switch(option)
{
         case 'A':
         break;
         case 'M':
         break;
         case 'I':
         break;
         case 'R':
         break;
}
//http://www.daniweb.com/techtalkforums/thread1769.html for random generator in range;
system("PAUSE");
return 0;
}

um... what is different between being male and female, except for the value of gender? I don't see what the problem is...

um its going to be for a textbased vid games.. its for the users benefit... the problem is realy that it runs both when the breaks should stop 1 from running...

ive had 3-4 ppl not including myself look at this in my class and we cant figue it out...

so, here's the output I get from running it (I made a few changes to the code, but nothing to affect the logic, and the lines starting with $ are where I start the program):

$ ./a.out 
Please choose your gender(M/F). M
You have chosen a male character. 
Please choose your class.(Mage,Fighter,Archer.[M,F,A]) F
You have chosen the Fighter.
 $ ./a.out 
Please choose your gender(M/F). F
You have chosen a female character.
 Please choose your class.(Mage,Fighter,Archer.[M,F,A]) A
You have chosen the Archer.

Is this output somehow incorrect?

And if you're wondering what changes I made to the source...
- I renamed the headers to <iostream> and <iomanip>, and also added the line using namespace std; after all the #includes
- I changed main() to int main() - I removed the system("pause") because it's not portable (mainly because it doesn't work on my computer)

commented: Good job --joeprogrammer +3

wow that was quick... umm.. it was running male then clas pick then female and class pick then the default(tho i think we gpot rid of the default.).

ill try that tho...

wow that was quick... umm.. it was running male then clas pick then female and class pick then the default(tho i think we gpot rid of the default.).

ill try that tho...

It Gives one more error in the switch statement!!
switch(option)
{
case 'A': break;
case 'M':
break;
case 'I':
break;
case 'R':
break;
}

you are using Option without assigning.. so you need to comment out this switch case also.

i got it to work... thanks for the help...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.