• Post Reply Bookmark Topic Watch Topic
  • New Topic

my user input is not being returned  RSS feed

 
kennith stomps
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, line 41 is supposed to return the variable i to line 9 where it is supposed to be displayed what the user selection is. Any idea why it is not displaying my selection? If I input i as 1,2,3, or 4 it says "invalid selection, please input correct operand" whereas it is supposed to display whatever digit i select as those are valid options.

 
Carey Brown
Saloon Keeper
Posts: 3328
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



If 'i' is 3, then the results will be true regardless of the other checks you are making because 'i' is not-equal-to 1.
 
kennith stomps
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The statement says that if i is not 1, 2, 3, or 4 to output that it is an invalid selection. It says that every selection is an invalid selection, including 3, so I do not understand what you are trying to say.

 
kennith stomps
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The question was, why would the code not be displaying my selection, and why is every selection invalid
 
Paul Clapham
Sheriff
Posts: 22835
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey already explained why your code classifies any number as an incorrect selection. you should go back and look at his post again.
 
kennith stomps
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How so? Carey posted

"else if (i != 1 || i !=2 || i!=3 || i!= 4){
then carey says
If 'i' is 3, then the results will be true regardless of the other checks you are making because 'i' is not-equal-to 1.

I don't understand what is incorrect about that statement? if i does not equal 1,2,3 or 4, the statement is incorrect. However, if I input i as 1, 2, 3, or 4. The statement is still incorrect, not true as carey says.

 
kennith stomps
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if (i != 1 || i !=2 || i!=3 || i!= 4){

is this not how you are to write if i does not equal 1 or if i does not equal 2 or if i does not equal 3 or if i does not equal 4?
 
Ron McLeod
Bartender
Posts: 1603
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kennith stomps wrote:if (i != 1 || i !=2 || i!=3 || i!= 4){
is this not how you are to write if i does not equal 1 or if i does not equal 2 or if i does not equal 3 or if i does not equal 4?

You have a problem with your logic.  You probably want to check if i is not equal to 1 AND i is not equal to 2 AND i is not equal to 3 AND i is not equal to 4.  You want to make sure all of your test conditions are true, not any.

As Carey mentioned, using OR, the test will always return true.
 
kennith stomps
Ranch Hand
Posts: 160
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, the and part makes it understandable, I just didn't know what

" If 'i' is 3, then the results will be true regardless of the other checks you are making because 'i' is not-equal-to 1." is supposed to mean.
 
Fred Kleinschmidt
Bartender
Posts: 571
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Consider the statement

That means "if i is not equal to 1, or if i is not equal to 2", then the statement is true.
It is the same thing as asking "if a is true, or if b is true". So if any one of the subclauses is true, the entire statement is true.

Now suppose i is equal to 3. Then the the first part of the statment is true, since i is not equal to 1, so the entire clause is true.

Now suppose that i is equal to 1. The first part is false, but the second part is true (since i is not equal to 2), so the entire statement is true.
The statement can never be false, since i can never be equal to both 1 and 2.
 
Campbell Ritchie
Marshal
Posts: 56576
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kennith stomps wrote:The statement says that if i is not 1, 2, 3, or 4 . . .
No, it doesn't say anything about if i is not 1, 2, 3, or 4. As Fred K has just told you, it says if i isn't 1 or i isn't 2 or i isn't 3 or i isn't 4 or ...
 
Knute Snortum
Sheriff
Posts: 4281
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A lot of the confusion comes from the way we might say something like: "If we don't go to the movies or we don't go out to eat, then..."  This is fine is casual speech, as the listener will understand what's being, but if we were to be strictly logical, we would say, "If we don't go to the movies and we don't go out to eat, then..."
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!