我正在尝试这样做,因此如果用户输入的数字小于 4 或大于 10,则会提示他们无效并输入新数字。我遇到的问题是,如果他们确实输入了正确的数字,它就不会继续到下一部分。这是我到目前为止所拥有的:
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <cstdlib>
#include <ctime>
int NewRandomNumber (int n);
void MakeQuestion (int n, int& a, int& b, int& atimesb);
bool UserAnswer (int a, int b, int atimesb);
void PrintScore (int numCorrect, int numAsked);
using namespace std;
int main()
{
string name;
int n;
string s;
cout << "Welcome to Multiplication Quiz 1000!" << endl;
cout << "Firstly what is your name?\n" << endl;
cin >> name;
cout << "\nHi " << name <<" !" << endl;
cout << "What difficulty would you like your quiz to be? Enter a value from [4 to 12]
\nwith 4 being the easiest:\n" << endl;
do
{
cin >> s;
n = atoi(s.c_str());
if ( n >= 4 || n <= 10)
if ( n < 4 || n > 10)
{cout << "invalid. try again" << endl;
}
{cout << "Ok" << endl;
cout << NewRandomNumber (4);
}
}
while ( n >= 4 || n <= 10);
return 0;
}
int NewRandomNumber (int n)
{
n = rand()% 10 + 1;
return (n);
}
void MakeQuestion (int n, int& a, int& b, int& atimesb)
{
}