如何在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'语句) –