2014-11-06 62 views
2

所以我一直在研究一個程序,要求用戶輸入一個值,當用戶退出代碼時輸入-99它假設返回所有數字和平均值的總值,但我「M難倒我的價值觀一直由前一個越來越overided ...這裏是我的代碼GML存儲用戶輸入

{ 
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); 
    } 

我如何使它所以它不會覆蓋舊?

回答

1

這是因爲每次執行while循環時都將值設置爲0。嘗試設置

value = 0; 

在開始執行直到循環之前。後

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; 
    } 
+0

感謝你,解決它 – user3215990 2014-11-09 20:02:00