still in the learning stages of R. Trying to setup a basic piece of code that will allow me to have a user enter numbers until they enter "0", at which time the program will sum entries and display to the user. This is what I have so far:
print ("Enter a number.enter 0 when finished")
enterednum <-as.integer(readLines(con=stdin(),1))
finalnum = 0
while (enterednum != 0){
print ("Enter another number. enter 0 when finished");
newnum <-as.integer(readLines(con=stdin(),1));
finalnum <- (enterednum + newnum)
}
print(paste("The sum of your numbers is", finalnum,"."))
The point of the exercise is to use while statements. While the false condition of the While statement (entering "0") works, any time the initial input is anything but 0, I receive a debug error for any lines after the while statement. Been wracking my brain and digging through here, but not been able to figure it out. Any help is appreciated.