How to calculate highest and lowest score using a while loop

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nuken
    New Member
    • Oct 2010
    • 16

    How to calculate highest and lowest score using a while loop

    the in input file is like
    2 80 97
    5 69 79 89 99 58
    7 60 70 80 90 100 0 59
    [
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    I don't see you referencing highscore or lowscore inside your while loop.

    Comment

    • Geocool
      New Member
      • Oct 2010
      • 2

      #3
      Code:
      if ( score > highscore )
          highscore = score;
      else if (score < lowscore )
          lowscore = score;
      Add the above code after "cin >> score;"

      You have declared lowerscore as 1 so if you enter 20 is bigger than your already given(1) lower score so it doesn't take it.

      I suggest to set first input as lowscore.
      like:

      Code:
      bool isfirstinput(true);
      while(!cin.eof()){
      ....
      ...
      cin >> score;
      if(isfirstinput==true)
      {
      lowscore=score;
      isfirstinput = false; // so it won't pass to lowscore again
      }
      ...
      I hope this helps... ;)

      Comment

      • nuken
        New Member
        • Oct 2010
        • 16

        #4
        I set lowscore equal to 100 and it works for the first one:

        Comment

        Working...