我需要一些帮助来找到该算法的问题。
该算法应该以10000个数字为输入,计算并输出小于1000的数字。然后计数并输出大于5000的数字。最后输出输入的平均值。如果太乱了,甚至制作一个新的和改进的。
谢谢!
less=0
more=0
total=1
for x = 0 to 10000
num= input ("enter a number")
if num < 1000 then
less = less + 1
else
more = more + 1
endif
total = num
next x
output ("less: "+ less)
output("more: "more")
average = total / 10000
output ("average: " + average)
缩进和一致的间距使它更易于阅读和理解。
使用0 to 10000
表示10001个数字。
您需要total = 0
和total = total + num
(从注释中)以获取正确的总和,并测试大于5000(也从注释中)以获取正确的计数。
一个output
语句的引号不正确,并且缺少运算符。
less = 0
more = 0
total = 0
for x = 1 to 10000
num = input ("enter a number")
if num < 1000 then
less = less + 1
else if num > 5000
more = more + 1
endif
endif
total = total + num
next x
output ("less: " + less)
output ("more: " + more)
average = total / 10000
output ("average: " + average)