• Post Reply Bookmark Topic Watch Topic
  • New Topic

Double answer Problem  RSS feed

 
Vin Ash
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys.
Ok first emersion into the program
got to ask to input age and day
then with given, I got to calculate the discount
when I input age Below 16 and over 65 I have no problems
All works fine
But when I enter between ages of 17 to 64, I get double answers , one right and one wrong of course
I went over it cm by cm and can get what is wrong
Any ideas
Thanks in advance

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

should be
 
Vin Ash
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey Brown wrote:Seems like

should be


When I change the two first || for &&, The programs does not go to the end. It stops have half and says build is successful and does not show any prices and discounts
If I put all || same results
If I put all && then I get double results for all like so
 
Carey Brown
Saloon Keeper
Posts: 3310
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like you're thrashing instead of thinking the logic through. For example, part of your original logic was

There is no age that satisfies both the left and right hand side of the expression. Age can't be both less than 17 AND greater than 64. Impossible. So you need to reexamine your logic.
 
Vin Ash
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
even if I write them on separate lines it makes no difference
 
Carey Brown
Saloon Keeper
Posts: 3310
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you write down in English (sorry, my native tongue) what logic you are trying to implement with this if statement? I might then be able to be of more help. I don't quite follow when you say "write them on separate lines".
 
Carey Brown
Saloon Keeper
Posts: 3310
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you give it an age of 17...
 
Carey Brown
Saloon Keeper
Posts: 3310
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
These two are logically identical so I'm guessing that this is not what you intended.
 
Vin Ash
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well with some tweaking this is what I have now (following your advice Carey Brown)


 
Vin Ash
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the problem seems to lie with the last part

Whenever I put someone age >=17 or age <=64

there is supposed to be no discount

but it does not go to that equation but retraces the one on top which gives 10%

I guess it is reading that one because the "choix" are the same

I even tried a plain else since it is the last equation but no result

 
Carey Brown
Saloon Keeper
Posts: 3310
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whenever I put someone age >=17 or age <=64


Your English description you are using OR, and as you can see from the table, AorB will always be true;

If you want to say: is varable V outside of the range of MIN and MAX, it would be

if you want to find it if it's between MIN and MAX, that would be
 
Vin Ash
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Carey
I resolved the problem. It was a bracket thing
But your logic thing did make me think as well so thanks for that as well
Thanks for the help
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!