"Moving" strings, ints etc.
Apr 11, 2010 at 3:49pm UTC
Edit: Read the end before the code.
Edit 2: Read second post for shorter example.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
int main ()
{
cout << "Welcome adventurer!\n\n[N]ew game\n[L]oad game\n[Q]uit\n\nType 'H' to get help.\n\n" ;
char MainMenu;
cin >> MainMenu;
switch (toupper (MainMenu))
{
case 'N' :
{
cout << "\n\nLoading...\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" ;
Sleep(1000);
goto char_gen_n;
}
case 'L' :
{
cout << "\n\nSave-Load fuction coming soon.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" ;
Sleep(4000);
return main ();
break ;
}
case 'Q' :
{
cout << "\n\nThank you for playing.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" ;
Sleep(4000);
return 0;
break ;
}
case 'H' ://Help.
{
cout << "\n\nType the letter in [X], to choose the option.\nFor example 'X' in the example.\nThat will work every time ther is letter in [].\n\nTry to get back to main menu.\n\n[B]ack\n\n" ;
back_training://Back training.
{
char backq;
cin >> backq;
switch (toupper (backq))
{
case 'B' :
{
cout << "\nGood job!\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" ;
Sleep(4000);
return main ();
break ;
}
default :
{
cout << "\nTry again!(By typing 'B')\n\n" ;
goto back_training;
break ;
}
}//End switch(Back)
}//End back_training.
}//End Help.
default :
{
return main ();
break ;
}
}//switch end.(Main menu)
char_gen_n://Character Creation_Name
{
cout << "\nPlease type your name here:\n" ;
string username;
cin >> username;
cout << "\n\nYour name is " << username << ".\n\n" ;
goto char_gen_g;
char_gen_g://_Gender (1=Male)(2=Female)
{
cout << "Please select your gender.\n\n[M]ale\n[F]emale\n\n" ;
char gender;
int int_gender;
cin >> gender;
switch (toupper (gender))
{
case 'M' :
{
cout << "\nYou are male.\n" ;
Sleep(3000);
cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" ;
int_gender=1;
goto he_or_she;
break ;
}
case 'F' :
{
cout << "\nYou are female.\n" ;
Sleep(3000);
cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" ;
int_gender=2;
goto he_or_she;
break ;
}
default :
{
goto char_gen_g;
break ;
}
}//End switch.
}//End gender.
}
Here is the code, now the question is can I move for example string from "char_gen_n" to "char_gen_g"? Or int value? If I can how?
Note: This is not the full code. So don`t wonder ie. "goto he_or_she;"
Last edited on Apr 12, 2010 at 1:16pm UTC
Apr 12, 2010 at 12:51pm UTC
Bump.
The question is simply how (if I indeed can.) I can set so that strings, int values and so on stay in whole code. For example if put following:
1 2 3 4 5 6 7 8 9 10 11 12
int main ()
{
string name;
cin >> name;
goto next_step;
next_step:
{
cout << "Hello " << name << ", nice to meet you." ; //Here comes error since program does not take the "name" from "int main () "
}
};
How can I fix that.
Last edited on Apr 12, 2010 at 1:28pm UTC
Apr 12, 2010 at 1:30pm UTC
Oh sorry to bother found out that above works fine. (In original code I had break;) so it didn`t work.
Topic archived. No new replies allowed.