C++编程 谢谢

来源:百度知道 编辑:UC知道 时间:2024/06/16 20:02:34
考试 出10道题 每道题有三次回答机会 都打错不给分 并且给出答案 并求最后的分数

#include<iostream>//加法题
#include<cstdlib>
#include<ctime>
using namespace std;
void main()
{
int sum1=0;
srand((unsigned int)time(NULL));
for(int i=0;i<10;i++)
{
int num1=rand()%20;
int num2=rand()%20;
cout<<num1<<"+"<<num2<<"=";
int sum=0;
cin>>sum;
int count=1;
do{
if(sum==(num1+num2))
{
cout<<"right!next one……"<<endl;
sum1+=10;
break;
}
else
{
cout<<"wrong,try again!"<<endl;
cout<<num1<<"+"<<num2<<"=";
cin>>sum;
count++;
}
if(count==3)
{
if(sum==(num1+num2))
{
cout<<"right!next one……"<<endl;
sum1+=10;
break;
}