Multiple if Statement

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.

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
32
33
34
35
36
37
38

#include <iostream>

using namespace 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;
	}
}

Last edited on
This code could be rewritten as:

1
2
3
4
5
6
7
8
9
10
11
#include <iostream>

using namespace 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.
Oh that easy! Thanks for the help i understand it now.
Topic archived. No new replies allowed.