Hi there, I am having some trouble understanding why my program is not working here. I am trying to do some simple if statements here entering two numbers, but it does not seem to be working. I want my program to do a particular thing here.
First, enter two numbers. If the two numbers both entered are zero, display "good". If the second number entered is "0", display "Not cool" and if the first number is "0", display "Error!". My problem is this, if I enter 0 and 5, it should display "Error" but it's not working! For some reason, it's working if I enter 5 and 0 because since the second number is considered zero, it should display "Not cool".
After some digging around, I naturally found a possible (I could be wrong) solution because if I enter 0 and 5, the first if statement passes and therefore does not go to the other if statement, but I thought to my knowledge in-order for the first nested if statement to pass, they BOTH need to be true. Is this not the case? Thanks a bunch.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
#include <iostream>
using namespace std;
int main()
{
int cool;
int test;
cin >> cool >> test;
if (cool == 0)
{
if (test == 0)
{
cout << "Good\n";
}
}
else if (test == 0)
{
cout << "Not cool\n";
}
else if (cool == 0)
{
cout << "Error!\n";
}
else
{
}
return 0;
}
|