• Post Reply Bookmark Topic Watch Topic
  • New Topic

Determining Adult Problem  RSS feed

 
Vin Ash
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys
working on program which has to determine
1.the average of the age of input people
2. how many are adult among them and write the number of adults only (example if I have 15 16 24 and 26..program has to write only 2 adults
now with first part, no problem
second part is the problem

how do I get the program to write the amount of people over 18 years
thanks

 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37469
539
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hint: you need another variable and an if statement to keep track of the number of adults.
 
Stephan van Hulst
Saloon Keeper
Posts: 7986
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's strange, I don't feel adult at all
 
Vin Ash
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks guys, I know I need an "if" but where do I put that
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37469
539
Eclipse IDE Java VI Editor
 
Manoj Kumar Jain
Ranch Hand
Posts: 198
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to check age of each student to determine if he/she is adult or not. Each time you encounter an adult you will increase the counter. As you are reading inputs in loop so you will
1. Have to check if age meets with adult criteria (if condition)
2. Have to increase the counter when age meets the condition(counter++) otherwise do nothing.

and off course all this will happen inside the loop unless you want to store ages of all students somewhere, which is not required.
 
Vin Ash
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys thanks
after banging my head for a while and your help I managed to get something right but now I have another problem

I can't seem to get the average of ages right
I know it has to do with the " age+=" on line 14 but I can't get that part right
If I leave the " age+=" my number of adults count is screwed but average age is fine
if I take it out " age=" my number of adults is good but then my average is screwed
how to go about this
thanks


 
Carey Brown
Saloon Keeper
Posts: 3318
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need two different variables: age, and sumOfAges.
 
Vin Ash
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks carey ..was not thinking about that one.
Thanks to everybody else for the invaluable help
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!