• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Double answer Problem

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Bartender
Posts: 11113
88
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Seems like

should be
 
Vin Ash
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 11113
88
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
even if I write them on separate lines it makes no difference
 
Carey Brown
Bartender
Posts: 11113
88
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 11113
88
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you give it an age of 17...
 
Carey Brown
Bartender
Posts: 11113
88
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 11113
88
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic