我正在编写一个程序,除了下面的函数外,一切正常。我很好奇怎样做才能使第一个循环的用户输入只能是 1 - 69,而第二个循环只能是 1 - 26。
我正打算执行一个 do/while 循环,但出现如下所述的错误。
//***********************************************
//Case 4 lets you input your own lottery numbers*
//***********************************************
void case4()
{
cout << numberprint << endl;
tickettop();
int array_pick[4];
int pballp;
for (int i = 0; i < 5; i++)
{
cout << evalue << i + 1 << space1;
do
{
cin >> array_pick[i];
} while (array_pick > 0 && array_pick <= 69); //Here is where I get an error for array_pick <= 69 (operand types are incompatible ( int * and int))
}
for (int i = 0; i < 1; i++)
{
cout << eball;
cin >> pballp;
}
cout << endl << endl;
ofs << endl;
ticketbottom();
ofs << bar << box << bar << endl;
}
最佳答案
int lottonumber;
ask: //goto label
cin >> lottonumber; //prompt value in console
//if lower than 1 or higher than 69, goto label
if (lottonumber < 1 || lottonumber > 69)goto ask;
人们不喜欢 goto
标签,但在这种情况下这不是问题。 While 循环和 for 循环的存在是为了使代码更易于理解和组织。 goto 标签不会使您的程序变慢或“变坏”,它只会使它更难组织。或者在这种情况下,更容易。
关于c++ - 无法设置用户可以输入的数字范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39984034/