I am using a switch statement that will decide from a random number what message to display.
I want the random number to be between 0 and 100 and then if the number is say between 1 and 10 to display a certain message.
here is my code
after the case statment I need something that does basically the function of
Example:
case < 10 :
case > 10 && < 20 :
case > 20 && < 30 :
and so on untill 100.
I am not familiar with the syntax to preform that opeation.
I tried storing those operations into variables and just placing the variables after case but the same error occured.
this is the error for the first case:
error C2059: syntax error : '<'
And this is the error for all the following cases:
error C2059: syntax error : '>'
I assume that I can't start the syntax with either the > or <. Do I need to enclose it in parenthesis?
I know in an If statment I could word it like this
and so on, but that is alot of code.
Can I impliment those operations into a switch statement, or do I have to use an If statement?
If I can use a switch, how would I do so?
I want the random number to be between 0 and 100 and then if the number is say between 1 and 10 to display a certain message.
here is my code
Code:
srand(time(0)); int messageSelect = 1+rand()%100; switch (messageSelect) { case .......... : cout << "I'm sorry but you lose. Try again!" << endl << endl; break; case .......... : cout << "You don't guess well on tests do you?" << endl; cout << endl; break; case .......... : cout << "Bad luck I guess. Try again!" << endl << endl; break; case .......... : cout << "The Greeks may think the gods don't favor you."; cout << " Try again!" << endl << endl; break; case .......... : cout << "You have yet to find the magic number."; cout << " Try again!" << endl << endl; break; case ..........: cout << "Wrong number. Try again!" << endl << endl; break; case .......... : cout << "Guess what! Try again!" << endl << endl; break; case .......... : cout << "Looks to me like you're gonna have to try again!"; cout << endl << endl; break; case ..........: cout << "Doesn't look to be in your favor."; cout << " Try again!" << endl << endl; break; case ..........: cout << "Your outcome looks bleak. Try again!"; cout << endl << endl; break; }
after the case statment I need something that does basically the function of
Example:
case < 10 :
case > 10 && < 20 :
case > 20 && < 30 :
and so on untill 100.
I am not familiar with the syntax to preform that opeation.
I tried storing those operations into variables and just placing the variables after case but the same error occured.
this is the error for the first case:
error C2059: syntax error : '<'
And this is the error for all the following cases:
error C2059: syntax error : '>'
I assume that I can't start the syntax with either the > or <. Do I need to enclose it in parenthesis?
I know in an If statment I could word it like this
Code:
if (messageSelect < 10) Statement.... else if (messageSelect is > 10 && < 20) Statement....
Can I impliment those operations into a switch statement, or do I have to use an If statement?
If I can use a switch, how would I do so?
Comment