这是我的代码:
var num, totalNum, averageNum, numItems, msg;
msg = "";
totalNum = 0;
numItems = 0;
while(true)
{
num = get_integer("Please enter a number. Enter -99 to quit.", "type here");
totalNum += num;
numItems += 1;
if (num == -99)
{
totalNum += 99;
msg += "Total is: " +string(totalNum) +"#";
averageNum = real(totalNum / numItems);
msg += "Average is: " +string(averageNum);
show_message(msg);
break;
}
}
现在,如果我输入数字 1 和 2,然后输入 -99 来打破循环,我得到的平均值是 1。我想得到实数,而不是整数。有什么帮助吗?