Search code examples
htmlinputstoragegml

GML Storing User Input


So I have been working on a program that ask the user to input a values and when the user exits the code by entering -99 its suppose to return the total Value of all the numbers and the average but I'm stumped My values keep getting overided by the previous one... here is my code

{
var user_Input;<br>
var output_msg;<br>
var count;<br>
var highest;<br>
var value;<br>
var total;<br>

count = 0;
do
   {
   user_Input = get_integer("Enter a number To add To the List(Enter -99 to    leave)",-99);
     if (user_Input == (-99)){
         continue}
         count += 1;
         value = 0;
         value = value + user_Input;
         average = value/count;
      }

     until(user_Input == (-99)){
     count -=1;
     user_Input = user_Input + 99;
     output_msg=("#Numbers Entered: " + string(count) + "##Total value of numbers: " +                       string(highest) + "## Average:" + string(average));`
     }
     show_message(output_msg);
     }

How Do I make it so it doesn't override the previous one?


Solution

  • This is because you are setting value equal to 0 every time the while loop is executed. Try setting

    value = 0;
    

    before you start the do until loop. Perhaps right after

    count = 0;
    

    like this:

    count = 0;
    value = 0;
    do{
       user_Input = get_integer("Enter a number To add To the List(Enter -99 to leave)",-99);
       if (user_Input == (-99)){continue}
       count += 1;
       value = value + user_Input;
       average = value/count;
      }