Hi there i'm completely beginner to c++.
Why does my other if statement (int y) not working properly?
the only thing that works is the int x.
When I try to run it 'int x' works perfectly fine and it prints the string on the screen. but when I put higher 'int y' does not work? What did I do wrong?
Someone explain why ? Thank you.
#include <iostream>
usingnamespace std;
int main()
{
int x = 0;
int y = 0;
int number = 0;
cout << "Enter a number here: " << endl;
cin >> number;
if (x >= 0)
{
if (x <= 100)
{
cout << "You entered a lower number " << endl;
return 0;
}
}
if (y >= 101)
{
if (y <= 200)
{
cout << "You entered a higher number " << endl;
return 0;
}
}
else
{
cout << "You didn't any enter a number " << endl;
}
}
#include <iostream>
usingnamespace std;
int main()
{
int number ;
cout << "Enter a number here: " << endl ;
cin >> number
cout << "You entered a lower number " << endl ;
}
and it would be functionally equivalent to what you've written. x and y are always the same value, so the same path through the code is always followed.