Copyright (c) 2016,烟台大学计算机学院.
All rights reserced.
文件名称:test.cpp
作者 :秦通
完成日期:2016.3.31
版本号 :VC++6.0
问题描述:提供十道加减乘除四种算术题目,输入答案,程序自动判断是否正确,最后显示答对几道题,
程序输入:
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int x,y,z,n,w,i,m;
n=0;
i=1;
for(i=1;i<=10;i++)
{
cout<<"第"<<i<<"道题:"<<endl;
srand(time(0));
x=rand()%100;
y=rand()%100;
z=rand()%4;
switch(z)
{
case 0: w=x+y; cout<<x<<"+"<<y<<"="; break;
case 1: w=x-y; cout<<x<<"-"<<y<<"="; break;
case 3: w=x*y; cout<<x<<"*"<<y<<"="; break;
default : cout<<x<<"/"<<y<<"="; w=x/y;
}
cin>>m;
if(m==w)
{
cout<<"right!"<<endl;
n++;
}
else
cout<<"wrong!"<<endl;
}
cout <<"您总共答对"<<n<<"道题,得"<<n*10<<"分。"<< endl;
return 0;
}
运行结果: