c语言交互式小学生口算题

mac2024-12-11  23

#include<iostream> #include<cstdio> #include<time.h> #include<cstdlib> using namespace std; int judge(int a,int b,int c) { if(a+b==c) return 1; else return 0; } void adt(int a,int b)//虽然我墙裂觉得这个自定义函数毫无意义 { printf("%d+%d=",a,b); } int main() { int i,a,b,c,chance,score=0; srand(unsigned(time(NULL))); for(i=1;i<=10;i++) { a=rand()%10+1; b=rand()%10+1; chance=3; while(chance--) { adt(a,b); cin>>c; if(judge(a,b,c)) { cout<<"Right"<<endl; score++; break; } else if(chance>0) cout<<"Try again!"<<chance<<"chances left!"<<endl; else cout<<"Sorry! No chance left! Try a new test!"<<endl; } } cout<<"Congratulations! You got "<<score<<" scores!"<<endl; system("pause"); return 0; }
最新回复(0)