kennith stomps

Ranch Hand

Posts: 160

posted 2 months ago

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.

kennith stomps

Ranch Hand

Posts: 160

kennith stomps

Ranch Hand

Posts: 160

posted 2 months ago

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

posted 2 months ago

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.

"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

posted 2 months ago

You have a problem with your logic. You probably want to check if

As Carey mentioned, using

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

*AND*

`i`is not equal to 1*AND*

`i`is not equal to 2*AND*

`i`is not equal to 3*. You want to make sure*

`i`is not equal to 4**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

Fred Kleinschmidt

Bartender

Posts: 571

9

posted 2 months ago

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.

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

posted 2 months ago

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..."All things are lawful, but not all things are profitable.