#include <iostream>
#include <string>
using namespace std;
int main()
{
string ops_str;
char ops_char;
int ops_int,result;
cout<<"Select the operator:\n"
<<"0:End\n"
<<"1:+\n"
<<"2:-\n"
<<"3:*\n"
<<"4:/\n"
<<"Please enter the corresponding number:";
while(cin>>ops_int)
{
//cin>>ops_int;
switch(ops_int)
{
case 1:
ops_char='+';
break;
case 2:
ops_char='-';
break;
case 3:
ops_char='*';
break;
case 4:
ops_char='/';
break;
default:
break;
}
int N=1+rand()%10,M=1+rand()%10;
int n(2);
cout<<N<<ops_char<<M<<"=";
cin>>result;
switch(ops_char)
{
case '+':
while(result!=N+M && n>0)
{
cout<<"Wrong!"<<n<<" more time:";
cin>>result;
n--;
}
if(n>=0)
cout<<"Right!\nSelect the operator:";
else
{
cout<<"Wrong!\n";
cout<<N<<ops_char<<M<<"="<<N+M<<'\n';
cout<<"Right!\nSelect the operator:";
}
break;
case '-':
if(N-M<0)
{
cout<<"Enter Wrong.";
cout<<"\nSelect the operator:";
}
else
{
while(result!=N-M && n>0)
{
cout<<"Wrong!"<<n<<" more time:";
cin>>result;
n--;
}
if(n>=0)
cout<<"Right!\nSelect the operator:";
else
{
cout<<"Wrong!\n";
cout<<N<<ops_char<<M<<"="<<N-M<<'\n';
cout<<"Right!\nSelect the operator:";
}
}
break;
case '*':
while(result!=N*M && n>0)
{
cout<<"Wrong!"<<n<<" more time:";
cin>>result;
n--;
}
if(n>=0)
cout<<"Right!\nSelect the operator:";
else
{
cout<<"Wrong!\n";
cout<<N<<ops_char<<M<<"="<<N*M<<'\n';
cout<<"Right!\nSelect the operator:";
}
break;
case '/':
while(result!=N/M && n>0)
{
cout<<"Wrong!"<<n<<" more time:";
cin>>result;
n--;
}
if(n>=0)
cout<<"Right!\nSelect the operator:";
else
{
cout<<"Wrong!\n";
cout<<N<<ops_char<<M<<"="<<N/M<<'\n';
cout<<"Right!\nSelect the operator:";
}
break;
}
}
system("pause");
}
#include <string>
using namespace std;
int main()
{
string ops_str;
char ops_char;
int ops_int,result;
cout<<"Select the operator:\n"
<<"0:End\n"
<<"1:+\n"
<<"2:-\n"
<<"3:*\n"
<<"4:/\n"
<<"Please enter the corresponding number:";
while(cin>>ops_int)
{
//cin>>ops_int;
switch(ops_int)
{
case 1:
ops_char='+';
break;
case 2:
ops_char='-';
break;
case 3:
ops_char='*';
break;
case 4:
ops_char='/';
break;
default:
break;
}
int N=1+rand()%10,M=1+rand()%10;
int n(2);
cout<<N<<ops_char<<M<<"=";
cin>>result;
switch(ops_char)
{
case '+':
while(result!=N+M && n>0)
{
cout<<"Wrong!"<<n<<" more time:";
cin>>result;
n--;
}
if(n>=0)
cout<<"Right!\nSelect the operator:";
else
{
cout<<"Wrong!\n";
cout<<N<<ops_char<<M<<"="<<N+M<<'\n';
cout<<"Right!\nSelect the operator:";
}
break;
case '-':
if(N-M<0)
{
cout<<"Enter Wrong.";
cout<<"\nSelect the operator:";
}
else
{
while(result!=N-M && n>0)
{
cout<<"Wrong!"<<n<<" more time:";
cin>>result;
n--;
}
if(n>=0)
cout<<"Right!\nSelect the operator:";
else
{
cout<<"Wrong!\n";
cout<<N<<ops_char<<M<<"="<<N-M<<'\n';
cout<<"Right!\nSelect the operator:";
}
}
break;
case '*':
while(result!=N*M && n>0)
{
cout<<"Wrong!"<<n<<" more time:";
cin>>result;
n--;
}
if(n>=0)
cout<<"Right!\nSelect the operator:";
else
{
cout<<"Wrong!\n";
cout<<N<<ops_char<<M<<"="<<N*M<<'\n';
cout<<"Right!\nSelect the operator:";
}
break;
case '/':
while(result!=N/M && n>0)
{
cout<<"Wrong!"<<n<<" more time:";
cin>>result;
n--;
}
if(n>=0)
cout<<"Right!\nSelect the operator:";
else
{
cout<<"Wrong!\n";
cout<<N<<ops_char<<M<<"="<<N/M<<'\n';
cout<<"Right!\nSelect the operator:";
}
break;
}
}
system("pause");
}