If switch statement fails?
I have this being called:
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
|
cin >> c;
switch(c)
{
case '1':
blacksmith();
town();
break;
case '2':
alchemist();
town();
break;
case '3':
forest();
town();
break;
case '4':
quest();
town();
break;
case '5':
stats();
town();
break;
}
| |
How can I make it so that if the player say enters "56" that it says that it was an invalid number? An else statement doesn't work.
you can have a default case. the break is optional in the end but i put it anyway.
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
|
cin >> c;
switch(c)
{
case '1':
blacksmith();
town();
break;
case '2':
alchemist();
town();
break;
case '3':
forest();
town();
break;
case '4':
quest();
town();
break;
case '5':
stats();
town();
break;
default:
cout << "everything else that fails gets called here" << endl;
break;
}
| |
Last edited on
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
|
cin >> c;
switch(c)
{
case '1':
blacksmith();
town();
break;
case '2':
alchemist();
town();
break;
case '3':
forest();
town();
break;
case '4':
quest();
town();
break;
case '5':
stats();
town();
break;
default:
cout << "Invalid entry";
}
| |
Thanks for your help!
Topic archived. No new replies allowed.