所以我一直在开发一个程序,要求用户输入一个值,当用户通过输入 -99 退出代码时,它应该返回所有数字的总值和平均值,但我很难过我的值不断被前一个值覆盖...这是我的代码
{
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);
}
我如何制作它才不会覆盖前一个?
最佳答案
这是因为每次执行 while 循环时都将 value 设置为 0。尝试设置
value = 0;
在开始 do until 循环之前。也许就在
count = 0;
像这样:
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;
}
关于html - GML 存储用户输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26769906/