C語言程式設計(第三版) 第六章 實驗題 2 任務4
阿新 • • 發佈:2018-12-18
#include <iostream>
#include<iomanip>
#include<time.h>
using namespace std;
int main()
{
int flag,n1;
char m;
double i=0,a=0,x,z,x1,x2;
CXW:
srand(int (time(0)));
x1=rand()%10+1;
x2=rand()%10+1;
n1=rand()%4;
if (n1==1)
m='+';
else if (n1==2)
m='-';
else if (n1==3)
m='*';
else if (n1==0)
m='/';
switch (m)
{
case '+':
cout << x1<<"+"<<x2<<"="<<"?";
z=x1 + x2;
cin >>x;
i++;
if (x==z)
{
cout <<"Right! "<<endl;
flag=0;
a++;
}
else
{
cout <<"Wrong! "<<endl;
flag=0;
}
break;
case '-':
cout << x1<<"-"<<x2<<"="<<"?";
z=x1 - x2;
cin >>x;
i++;
if (x==z)
{
cout <<"Right! "<<endl;
flag=0;
a++;
}
else
{
cout <<"Wrong! "<<endl;
flag=0;
}
break;
case '*':
cout << x1<<"*"<<x2<<"="<<"?";
z=x1 * x2;
cin >>x;
i++;
if (x==z)
{
cout <<"Right! "<<endl;
flag=0;
a++;
}
else
{
cout <<"Wrong! "<<endl;
flag=0;
}
break;
case '/':
cout << x1<<"/"<<x2<<"="<<"?";
z=x1 / x2;
cin >>x;
i++;
if (x==z)
{
cout <<"Right! "<<endl;
flag=0;
a++;
}
else
{
cout <<"Wrong! "<<endl;
flag=0;
}
break;
}
if (flag==0&&i<10)
goto CXW;