Avuya Mxoli

Avuya Mxoli

  • NA
  • 236
  • 206.1k

The sum that is greater than the user input

Sep 2 2011 12:23 AM
Hello everyone, this is a class exercise that we were given to go think about and then we will share the answers in class...We are going to accept user input and then loop through adding to sum every time and checking if the value of sum is not bigger than the user input using pseudocode so here is my attempt and it is failing me(tested in c#):
accept input
i=1,sum = 0;
while sum<n
  do
     sum = 0;
    FOR i =1 and i <= sum
      sum = sum +i
       i++
   END FOR
 display (sum)

I used 10 to test, the sum is supposed to stop at 15 because:1+2+3+4+5 = 15 but I got 17 I dont knw what im missing plz help
Thanks


Answers (2)