标签:
#include<iostream>
using namespace std;
#include<stdlib.h>
#include<time.h>
int main()
{
int a,b,ans,res,c1=0,c2=0,c3=0,c4=0,t,i,N;
int p;
srand((unsigned)time(NULL));
while(1)
{
cout<<"\n--小学生四则运算练习题--\n";
cout<<"--1.加法运算--\n";
cout<<"--2.减法运算--\n";
cout<<"--3.乘法运算--\n";
cout<<"--4.除法运算--\n";
cout<<"--5.退出练习--\n";
cout<<"--请输入数字1-5:--\n";
cin>>p;
switch(p)
{
case 1:
cout<<"--请进行加法运算--\n";
cout<<"--请输入题目个数--\n";
cin>>N;
for(i=1;i<=N;i++)
{
a=rand()%99+1;// rand()%a的结果最大为a-1*
b=rand()%99+1;
res=a+b;
cout<<a<<"+"<<b<<"=";
cin>>ans;
if(ans==res)
{
cout<<"你答对了!\n";
c1++;
}
else
{
cout<<"你答错了!\n";
cout<<"正确答案是:"<<res<<endl;
}
}
break;
case 2:
cout<<"--请进行减法运算--\n";
cout<<"--请输入题目个数--\n";
cin>>N;
for(i=1;i<=N;i++)
{
a=rand()%99+1;
b=rand()%99+1;
if(a<b)
{
t=a;a=b;b=t;
}
res=a-b;
cout<<a<<"-"<<b<<"=";
cin>>ans;
if(ans==res)
{
cout<<"你答对了!\n";
c2++;
}
else
{
cout<<"你答错了!"<<endl;
cout<<"正确答案是:"<<res<<endl;
}
}
break;
case 3:
cout<<"--请进行乘法运算--\n";
cout<<"--请输入题目个数--\n";
cin>>N;
for(i=1;i<=N;i++)
{
a=rand()%99+1;
b=rand()%99+1;
res=a*b;
cout<<a<<"*"<<b<<"=";
cin>>ans;
if(ans==res)
{
cout<<"你答对了!\n";
c3++;
}
else
{
cout<<"你答错了!"<<endl;
cout<<"正确答案是:"<<res<<endl;
}
}
break;
case 4:
cout<<"--请进行除法运算--\n";
cout<<"--请输入题目个数--\n";
cin>>N;
for(i=1;i<=N;i++)
{
a=rand()%99+1;
b=rand()%99+1;
res=a/b;
cout<<a<<"/"<<b<<"=";
cin>>ans;
if(ans==res)
{
cout<<"你答对了!\n";
c4++;
}
else
{
cout<<"你答错了!"<<endl;
cout<<"正确答案是:"<<res<<endl;
}
}
break;
case 5:goto END;
}
}
END:cout<<"再见!\n";
return 0;
}
标签:
原文地址:http://www.cnblogs.com/10Watson/p/4385667.html