Can we include if else in switch statements

In this code getting "expected a statement" error under case 1:
Please help guys:


#include <iostream>
#include<ctime>
using namespace std;

int main()

{
unsigned short num1, num2, n, k=0, op,check;
short result, cresult;

srand(time(NULL));

cout << "Enter any number of your choice (3 to 30)?";
cin >> n;

switch (check)
{
case 1:
if (n > 30 || n <= 3 )
cout << "You need to enter more than or equal to 3 and less than 30";
break;
else
continue;
}

for (int i=0;i<n;i++)

{

num1 = rand()%100;
num2 = rand()%100+1;
op = (rand()%4)+1;

switch(op)
{

case 1:
cout << num1 << "+" << num2 << "=";
cresult = num1 + num2;

break;

case 2:

cout << num1 << "-" << num2 << "=";
cresult = num1 - num2;

break;

case 3:

cout << num1 << "*" << num2 << "=";
cresult = num1 * num2;

break;


case 4:

cout << num1 << "/" << num2 << "=";
cresult = num1 / num2;

break;
}

cin>>result;
if (result == cresult)
{
k++;
cout << "You have entered correct answer!!! " << endl;
}
else
cout<<"incorrect,"<< cresult <<"was the answer"<<endl;

}

cout << "Success rate is :" << (k*100/n) << " % " << endl;
system ("pause");
return 0;
}
You probably meant to have curly braces around your if statement body:
1
2
3
4
5
6
7
if (n > 30 || n <= 3 )
{
    cout << "You need to enter more than or equal to 3 and less than 30";
    break;
}
else
    //continue; // Wait, what? You can't have 'continue' when there's no loop 
Okay. Thank you for correct me. What could be the possible correction in case I want to continue running the program if user enters the correct range of numbers (i.e, 3-30)?
I got the solution!!!
Topic archived. No new replies allowed.