随机数——加法做题
#include <bits/stdc++.h> using namespace std; int main() { int a,b,e; double c,d = 0; double f; cout<<"你想做几道题?"; cin>>c; for(int i = 1;i<=c;i++){ srand(time(0)); a = rand()%90+10; b = rand()%90+10; cout<<a<<"+"<<b<<"="; cin>>e; if(a+b==e){ d++; cout<<"恭喜你!!!答对一道题!!!得分+1分"<<endl; }else{ cout<<"答错了,不加分,正确的答案是"<<a+b<<"加油!!!"<<endl; } } cout<<"你的总分是"<<d<<"分"<<endl<<"一共做对了"<<d<<"道题"<<endl; f = d/c; cout<<"正确率是"<<f*100<<"%"<<endl; if(d/c>=0.9){ cout<<"优秀!!!"; }else if(d/c>=0.5){ cout<<"及格"; }else{ cout<<"再练练"; } return 0; }