如何在for循環中只運行其中一個if語句?例如,我有5輸入...我只是希望它再打印五......但每當我運行這段代碼,如果statement..please幫我如果for循環中的語句
#include <iostream>
#include <cstdio>
using namespace std;
int main() {
// Complete the code.
int a;
int b;
cin >> a;
for (a = 0; 0<a<10; a++)
{
if (a == 1)
{
cout << "one";
}
if (a == 2)
{
cout << "two";
}
if (a == 3)
{
cout << "three";
}
if (a == 4)
{
cout << "four";
}
if (a == 5)
{
cout << "five";
}
if (a == 6)
{
cout << "six";
}
if (a == 7)
{
cout << "seven";
}
if (a == 8)
{
cout << "eight";
}
if (a == 9)
{
cout << "nine";
}
else if (a > 9 && a%2 == 0)
{
cout << "even";
}
else if (a > 9 && a&2 != 0)
{
cout << "odd";
}
}
return 0;
}
你想實現什麼?你正在輸入a,但是在循環中再次初始化爲0 – Pirate
刪除'for 'loop。 –
你需要找到一個[良好的初學者書](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list)並閱讀條件表達式。在(不必要的)'for'循環中是不正確的。在閱讀本書時,關於'switch'語句的紅色和數組(你不需要一大串'if-else'或'switch'語句) –