我试图让这段代码的工作:C++做while循环不工作
#include <iostream>
using namespace std;
int main()
{
int i;
do
{
cout << ("please enter a number between 1 and 10");
cin >> i;
} while(i > 10 && i < 1)
cout << "the square of the number you have entered is " << i*i;
}
基本上,这个想法是,用户输入1和10之间的数字虽然数目不是1之间10,它一直要求用户在这些值之间输入一个数字。然后,当数字在这些值之间时,它被平方并返回给用户。
我不明白为什么这不工作
任何帮助表示赞赏
将条件从“和”更改为“或”。 – Meccano
请仔细考虑一下您的代码。 –
我怎么能同时大于10和小于1? –