• Post Reply Bookmark Topic Watch Topic
  • New Topic

question about read integer.  RSS feed

 
ivan auyoung
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basically i have a question ask me to write a program that read integer from keyboard until a negative number is entered, and then print out the max and min out of the number i have entered.
This is what i have done already which works, but i need to ignore the negative number when print out max and min...which i dont know how to do so. when i compile this program now it will always give me the negative number i enter at the end as minimum. which i need to ignore
Also if negative number is entered at once the program should print a error message say max and min are undefined.

I have read through some guide online and cant found solution to this 2 program..thanks for any help
 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe you could move the test for a negative number to a better location.
 
Stephan van Hulst
Saloon Keeper
Posts: 7991
143
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ivan.

Keywords are named the way they are, so they resemble spoken language. When a control flow statement doesn't really read nicely (like "while true"), you should probably rethink what you should write.

How often do you want to repeat the loop? While the input is non-negative.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!