#include<iostream>
#include<time.h>
#include<stdio.h>
using namespace std;
void main()
{
int t,num,a,n,i,b;
srand(time(NULL));//根据时间产生随机数
for(i=0;i<10;i++)
{
a=rand()%100;//0-100随机一个数赋值
loop:b=rand()%100;//0-100随机一个数赋值????????
n=rand()%4;
switch(n)
{
case 0:cout<<"第"<<i<<"题"<<endl;
cout<<a<<"+"<<b<<"=";
t=a+b;
break;
case 1:cout<<"第"<<i<<"题"<<endl;
cout<<a<<"-"<<b<<"=";
t=a-b;
break;
case 2:cout<<"第"<<i<<"题"<<endl;
cout<<a<<"*"<<b<<"=";
t=a*b;
break;
case 3:cout<<"第"<<i<<"题"<<endl;
cout<<a<<"/"<<b<<"=";
t=a/b;
break;
if(b==0) goto loop;t=a/b;break;
}
do
{
cin>>num;
if(num==t)
{
cout<<"答案正确"<<endl;
}
else
{
cout<<"答案错误!正确答案是:"<<t<<endl;
}
}while(num!=t);
}
}
除法除不尽时会陷入死循环 ;答案错误不会继续出题,在思考解决方案
原文地址:https://www.cnblogs.com/yh99/p/9752030.html
时间: 2024-10-13 14:55:38