#include<iostream>
#include<stdlib.h>
#include <time.h>
using namespace std;
void main()
{
int ok=0,did=0;
char contin='y';
do{
srand((unsigned)time(NULL));
int first,second;
first=rand()%10;
second=rand()%10;
cout<<first<<"+"<<second<<"=?";
int answer,correct;
cin>>answer;
did++;
correct=first+second;
if(answer==correct)
{
cout<<"ok!"<<endl;
ok++;
}
else
cout<<"No!answer="<<correct;
cout<<"continue or not?(y,n)";
cin>>contin;
if(contin=='Y')
contin='y';
}while(contin=='y');
cout<<"did="<<did<<",ok="<<cout<<ok<<",score="
<<((ok==0)?0:ok/float(did)*100)<<endl;
}
#include<stdlib.h>
#include <time.h>
using namespace std;
void main()
{
int ok=0,did=0;
char contin='y';
do{
srand((unsigned)time(NULL));
int first,second;
first=rand()%10;
second=rand()%10;
cout<<first<<"+"<<second<<"=?";
int answer,correct;
cin>>answer;
did++;
correct=first+second;
if(answer==correct)
{
cout<<"ok!"<<endl;
ok++;
}
else
cout<<"No!answer="<<correct;
cout<<"continue or not?(y,n)";
cin>>contin;
if(contin=='Y')
contin='y';
}while(contin=='y');
cout<<"did="<<did<<",ok="<<cout<<ok<<",score="
<<((ok==0)?0:ok/float(did)*100)<<endl;
}
本文介绍了一个使用C++编写的简易加法测验程序,该程序能够随机生成两个0到9之间的整数并要求用户输入它们的和。程序会记录用户的答题数量和正确率,并在用户选择结束练习时显示统计结果。

779

被折叠的 条评论
为什么被折叠?



