0
本质上,我想将所有用户输入保存到数组中,并在用户输入0时添加它们。我不知道该怎么做。在我的脚本中,每次都不可避免地改变x值。将用户输入值保存到数组中
这里是我的脚本至今:
print("This program will sum a series of numbers.")
x <- 1:100
num <- c(x)
while (num[x] != 0) {
print("Enter the next number (enter 0 when finished)")
num[x] <- as.numeric(readLines(con=stdin(),1))
}
sum <- sum(num)
print(paste("The sum of your numbers is", sum))
我得到这个错误:
In while (num[x] != 0) { : the condition has length > 1 and only the first element will be used
有人可以帮我吗?
哇!非常感谢。 – Tina