This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin for Android App Development and have Peter Sommerhoff on-line!
See this thread for details.
Win a copy of Kotlin for Android App Development this week in the Kotlin forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

storing values within a loop  RSS feed

 
Ranch Hand
Posts: 424
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
really battling with the logic in this for loop exercise

Prompt the user for the number of numbers they want to enter. Read in each of the number. When all the number have been entered display: the average, the highest number, the number that were divisible by 3, and the total



what i cant work out is how to store each user input in a variable within the loop and not allowed to use lists

any push in the right direction would greatly be appreciated
 
author & internet detective
Posts: 39129
723
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jon,
Start with total. That's the easiest. Could you create a variable outside the loop and update it each time you go through the loop to keep a running total?

Once that works, you can start to think about what variables you would need for the other things in the assignment.
 
jon ninpoja
Ranch Hand
Posts: 424
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi jeanne

yes i realise that i dont need every value stored in a variable
i have just created a total
and total = total + numberAdded
or total += numberAdded

trying to work out how to get the highest value in the numbers now
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!