View Single Post
Join Date: Apr 2006
Posts: 5,051
Reputation: John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold 
Solved Threads: 332
Team Colleague
John A's Avatar
John A John A is offline Offline
Vampirical Lurker

Re: finding the smallest number

 
0
  #2
Nov 12th, 2006
You can't do this:
  1. if ((menuItem >= 'A' || 'a') && (menuItem <= 'C' || 'c'))
(Well you can, but the results aren't going to be what you expect.)
You have to write out each expression:
  1. if ((menuItem >= 'A' || menuItem <= 'a') && (menuItem <= 'C' || menuItem <= 'c'))


  1. while (number != SENTINEL)
  2. { // open while 3
  3. counter++;
  4. cin >> number;
  5.  
  6. { // why do you have these braces
  7. cin >> number; // you already did a cin above ^_^
  8. if (number < temp2) // temp2 has never been initalized in this section!
  9. // how I would do it is set temp2 to -99, and then do the following if:
  10. // if (number < temp2 || temp2 == -99) { ...
  11. temp2 = number;
  12. } // you really don't need them
  13. }
Also, the way you're doing that loop, -99 is registered as the "lowest number" because it only bales out after it's done the comparison with temp2.

Not unnormal (you don't really need to worry about this), but when you input especially large numbers, it throws the program into an endless loop that has to be manually terminated.

[edit]By the way, in the menu loop, you need to somewhere reset your variables, because otherwise if you try to run section B twice, for example, you'll find that it doesn't allow input -- it just jumps right to the final output.[/edit]
Last edited by John A; Nov 12th, 2006 at 11:20 pm.
"Technological progress is like an axe in the hands of a pathological criminal."

All my posts may be freely redistributed under the terms of the MIT license.
Reply With Quote