switch case break

CAN YOU PLEASE HELP ME FIX MY CODES ASAP PLEASE TYVM :(



#include <iostream>
using namespace std;

int main ()
{
int number = 0;
cout<<"Enter a number between 1 - 5: ";
cin>>number;
char option = 0;


switch(number)
{
case '1' :
cout << "Excellent! :)" << endl;
break;
case '2' :
cout << "Masterful! :)" << endl;
break;
case '3' :
cout << "Incredible! :)" << endl;
break;
case '4' :
cout << "Superb! :)" << endl;
break;
case '5' :
cout << "Wonderful! :)" << endl;
break;
default :
cout << "Invalid!!! >.<" << endl;
}

cout<<"Would you like to continue? (Y for YES and N for NO): ";
cin>>option;

switch(option)
{
case 'Y' : case 'y' :
cout<<"WELCOME BACK!! :D" << endl;
break;
return main();

case 'N' : case 'n':
cout<<"Thank you!" << endl;
break;
return 0;
default :
cout << "Invalid!!! >.<" << endl;
return main();

}

return 0;
}
What's wrong with it?

And don't ever call main() like you have in your second switch statement.. Use a loop of some sort.

edit. okay, here's a clue:

case '1':
You are currently testing for the character '1', not the number.
Last edited on
How will it technically look like man? Thanks
i'd get your switch working first and then worry about returning flow back to the top, but basically you want your whole code in a while loop.

1
2
3
4
5
6
7
8
9
10
11
12
13
bool keepLooping(false);


do
{
....
.....
default :
cout << "Invalid!!! >.<" << endl;
keepLooping = true;
...
...
}while (keepLooping);


that kinda thing.
Last edited on
Okay Thanks I get it haha
Topic archived. No new replies allowed.