Hey Guys,
This is my first post here as I`m learning a programming language for the first time and I`m encountering a nasty problem:
I intend to use the "if" function to split different types of situations but it seems like i have a fault in my statements because the program doesnt do what I intend to make it do. Here is the code, it will explain my problem:
The problem is when I run the program and I enter a value of x bigger than 10 I still get the cout as if the statement was true. Same happens if I enter a value of y which is not 1 or 2 or 3. I still get "x is smaller than 11 and y is 1 or 2 or 3" . What did I do wrong. I want to make the program give "x is smaller than 11 and y is 1 or 2 or 3" when it is true but how do I write this in a statement that will be used in the right way by the compiler?Code:# include <iostream> using namespace std; int main() { int x; int y; cin >> x; cin >> y; if (x<=10 && y==1 || 2 || 3) cout <<" x is smaller than 11 and y is 1 or 2 or 3"; else cout <<" x is not smaller than 11 or y is not 1 or 2 or 3"; return 0; }
I hope that I`m making myself clear because I`m new to programming. It would help me alot if someone could help get rid of my problem.
Greetings,
A beginner programmer



LinkBack URL
About LinkBacks



[Strange as it may seem, I think one of the ways I learned programming was *answering* questions on CBoard. You'd be surprised how much you can learn that way.