小学生加减乘除

来源:互联网 发布:.wang域名值得投资吗 编辑:程序博客网 时间:2024/04/28 13:17

/*  Copyright  (c)  2016

*    All rights reserved

*    文件名称:3.cpp

*   作者:刘丽

*   完成日期:2016年 3  月 17日

*   版本号: v1.0

*

*   问题描述:随机出10道0~20之间的加减乘除题,并检测用户答案是否正确

*/

#include <iostream>#include<ctime>#include<stdlib.h>using namespace std;int main(){int i,panduan,a,b,sum;char fu;double sum2;    srand(time(0));for(i=0;i<10;i++){a=rand()%99;b=rand()%99;switch(rand()%4){case 0:fu='+';   sum=a+b;break;case 1:fu='-';   sum=a-b;break;case 2:fu='*';   sum=a*b;break;case 3:fu='/';   sum2=1.0*a/b;}cout <<a<<fu<<b<<'=';cin >>panduan;       if(panduan==sum && fu!='/')cout<<"right"<<endl;   else if(panduan==sum2 && fu=='/')   cout<<"right"<<endl;   else cout<<"wrong"<<endl;}    return 0;}

0 0