Ok, I have an if, and the user enters a value outside of the range.....

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • abueno
    New Member
    • May 2009
    • 16

    Ok, I have an if, and the user enters a value outside of the range.....

    Ok, I have an if statement, and the user enters a value outside of the range....
    say:

    int sco; //Variable used for score.

    if(sco< 0 || sco > 100)
    {
    cout<<"Error, You have to enter on the range 0-100\n";
    // I want to be able to subtract the last input from the total
    // without affect the other valid amounts.
    // So, I was thinking in:

    ave--;
    scomax=-sco; // This is wrong because makes my score to zero, and
    in the average variable, instead of subtract 1, subtract 2.


    }

    else

    ave++;

    scomax+=sco;
    total=comax/ave; // This formula is right when is a valid input, but my negative formula is bad.



    // Thank's 4 the comments.
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    If sco is out of range then don't include it into ave and scomax, then you don't have to try and subtract it which is hard (if not impossible).

    Comment

    • abueno
      New Member
      • May 2009
      • 16

      #3
      Thank you Banfa,

      I will try to assign different name variables, to see if that helps....and I will let sco, only for the valid input.

      Comment

      • whodgson
        Contributor
        • Jan 2007
        • 542

        #4
        Consider the following which rejects invalid input
        while(sco is outside required range)
        {
        //do stuff here
        }

        Comment

        Working...