码迷,mamicode.com
首页 > 其他好文 > 详细

个人项目3

时间:2018-11-01 16:54:27      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:bre   pac   div   and   namespace   ios   图片   bubuko   ima   

#include<iostream>
#define HOW 10
using namespace std;
char get_oper(int n)
{
switch(n)
{
 case 0:return ‘+‘;
 case 1:return ‘-‘;
 case 2:return ‘*‘;
 case 3:return ‘/‘;
}
}
int main()
{
int num1=0,num2=0,count=0;
float user_answer=0,right_answer=0;
int operators=0; //0:+ 1:- 2:* 3:/
for(int i=1;i<=HOW;i++)
{
 
     num1=rand();
 num2=rand();
 operators=rand()%4;
 if(operators==3)num1=num2*(rand()%100);
 
 cout<<i<<":? "<<num1<<get_oper(operators)<<num2<<"=";
 cin>>user_answer;

 switch(operators)
 {
 case 0:right_answer=num1+num2;break;
 case 1:right_answer=num1-num2;break;
 case 2:right_answer=num1*num2;break;
 case 3:right_answer=num1/num2;
 }
 
 if(right_answer==user_answer)
 {
 cout<<"RIGHT"<<endl;
 count++;
 }
 else
 cout<<"WRONG"<<endl;
}

cout<<"Right:"<<count<<"? Wrong:"<<HOW-count<<""<<count<<"/"<<HOW<<"="<<count/HOW;
return 0;
}
技术分享图片

 

个人项目3

标签:bre   pac   div   and   namespace   ios   图片   bubuko   ima   

原文地址:https://www.cnblogs.com/zzy0823/p/9889940.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!