我試圖讓這段代碼的工作: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? –