• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

test score calculator while loop

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to make a calculator that asks a user how many test scores will be entered, prompt the user to enter a score for the amount of scores to be entered, add the scores, and average the scores. If the user enters and invalid score, one that is above 100, the program should display an error message and not add the entry to the total number of scores or the added scores. I've gotten it to do everything I need until an invalid score is entered. Can anyone help me figure out how to tell it that if the score is over 100, do not add it to the score count or total. Here is what I have so far:



Thanks for any help figuring this out.
 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Can anyone help me figure out how to tell it that if the score is over 100, do not add it to the score count or total. Here is what I have so far:


Your code already handles that situation, what it doesn't do is get the user to enter a valid score instead of the invalid one. The problem is you increment the loop counter whether the input is valid or not, you may want to move the increment so it only happens if the input is valid.
You may also want to look at what happens is someone enters a negative number or a number of scores that is less than 1.
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've only seen two problems

a) What sir Docherty has said.


b) remember always that int / int will return an int, so the fraction part of the number is lost even if you "cast" it to double. To solve this make the average operation int /double, double/int or double/double


 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic