【发布时间】:2012-12-07 01:47:54
【问题描述】:
我的if 语句相互冲突时遇到问题。这是我的代码:
std::cout << "1) Option 1\n";
std::cout << "2) Option 2\n";
std::cout << "3) Option 3\n";
std::cout << "4) Option 4\n";
std::cout << "Type your choice and hit ENTER \n";
std::cin >> Choice;
if(Choice == 1);
{
std::cout << "Blah Blah\n";
}
if(Choice == 2);
{
std::cout << "Blah Blah\n";
}
if(Choice == 3);
{
std::cout << "Blah Blah\n";
}
if(Choice == 4);
{
std::cout << "Blah Blah\n";
}
我的意思是:它会忽略我的 if 语句并运行我的所有代码,这样它就会打印出来:
Blah Blah
Blah Blah
Blah Blah
Blah Blah
我的错误是什么?
【问题讨论】:
-
ifs 后面有分号。
-
而且,您应该阅读编译器警告。
标签: c++ visual-c++ if-statement