【发布时间】:2016-04-10 05:00:56
【问题描述】:
我一直在尝试做一个包含 10 个问题的随机数数学测验,但我的循环并没有只停留在第一个问题上。
我正在尝试一次循环一个问题,当用户回答问题 1 时,它会转到问题 2,依此类推,直到回答完所有 10 个问题,并且每个正确答案都将加到 1 分每个问题。谁能帮我解决这个问题?
编辑:1 好的,我按照你说的那样更改了代码,对吗?
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
int Player = 0;
int question = 1;
int nquestion = 10;
int choice = 0;
int qanswere1 = 0;
int panswere1 = 0;
int num1 = 0;
int num2 = 0;
int score = 0;
cout << "Lets Start" <<endl;
cout << "[1] Addition" <<endl;
cout << "[3] End" <<endl;
cout << "Choose: ";
cin >>choice;
if(choice == 1){
choice = 0;
cout << "Level" <<endl;
cout << "[1] Easy (1 - 10)" <<endl;
cout << "Choose: ";
cin >> choice;
while(choice == 1){
for(question = 1; question <= nquestion; question = question + 1 ){
num1 = rand()%10 +1;
num2 = rand()%10 +1;
cout<<num1<<"+"<<num2<<endl;
qanswere1 = num1 + num2;
cin>>panswere1;
}}
if(panswere1 == qanswere1){
score = score + 1;
}
else{
}
return 0;
}
}
即使使用此代码,它仍然超过 10 个问题,我做错了什么..
【问题讨论】:
标签: c++