- //是不是少了个头文件,,试试我给你修改了的代码~~
- //这是C++语言吧~
- #include<iostream>
- #include<cstdlib>
- #include<ctime>
- using namespace std;
- int score=0;
- void jisuan(int a,int b)
- {
- int count=1,sum,t,n;
- if((a+b)%2==0)
- { n=3;
- sum=a+b;
- cout<<"请计算:"<<a<<"+"<<b<<"=";
- while(n--)
- {
- cin>>t;
- if(t==sum)
- {if(count==1)
- score+=10;
- if(count==2)
- score+=7;
- if(count==3)
- score+=5;
- return ;
- }
- else
- { if(count!=3)
- cout<<"您的答案好像不对哦,请重新输入:";
- else
- { cout<<"您已经错了三次.."<<endl;
- cout<<"正确答案是:"<<sum<<endl;
- return ;
- }
- count++;
- }
- }
- }
- else
- { n=3;
- if(a<b)
- { t=a;
- a=b;
- b=t;
- }
- sum=a-b;
- cout<<"请计算:"<<a<<"-"<<b<<"=";
- while(n--)
- { cin>>t;
- if(t==sum)
- {if(count==1)
- score+=10;
- if(count==2)
- score+=7;
- if(count==3)
- score+=5;
- return ;
- }
- else
- { if(count!=3)
- cout<<"您的答案好像不对哦,请重新输入:";
- else
- { cout<<"您已经错了三次.."<<endl;
- cout<<"正确答案是:"<<sum<<endl;
- return ;
- }
- count++;
- }
-
- }
- }
- }
- int main()
- { int n=10;
- int a,b,i,j,sum;
- while(n--)
- {
- srand(unsigned(time(0)));
- a=rand()%50;
- srand(unsigned(time(0)));
- b=rand()%49;
- while(1)
- {
- if(a+b<50)
- break;
- if(a>0)
- a--;
- if(b>0)
- b--;
- }
- jisuan(a,b);
-
- }
- cout<<"您的成绩为:"<<score<<endl;
- if(score>=90)
- cout<<"******************SMART******************";
- else if(score>=80&&score<90)
- cout<<"******************GOOD******************";
- else if(score>=70&&score<80)
- cout<<"*******************OK*******************";
- else if(score>=60&&score<70)
- cout<<"******************PASS******************";
- else if(score>=60&&score<70)
- cout<<"************TRY AGAIN**************";
- return 0;
- }
复制代码 |