I'm having issues with my if
statements running into each other. Here is my code:
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";
}
By running into each other I mean: it will just ignore my if
statements and run all of my code so it would just print out:
Blah Blah
Blah Blah
Blah Blah
Blah Blah
What is my mistake?
Your semicolons need to be removed, they are terminating the if statement.
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";
}
You could use else ifs as well to clean up your code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With