1
我一直在试着用10个问题做一个随机数字测验,但是我的循环并没有停止,只是第一个问题。如何用C++中的10个问题进行随机数字测验?
我试图让循环一次一个问题,并且当用户回答question1时,它将进入question2等等,直到所有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个问题,我是做错了什么
..
THX的作品!但我怎么能限制到10现在超过10现在对不起,如果我没有理解它 –
@genesia假设你已经将10分配给你的变量'nquestion',循环将运行10次。 –
不要忘记接受答案,如果它可以解决你的疑问:) –