Undefined method for 'n' in ruby while loop -


i trying write algorithm solve math problem Σ n = 1 49 of n(n+1). keep getting error "undefined method 'n' main object"

def solver(n)   sum = 0   while n < 49     temp = n(n+1)     n+=1     sum = sum + temp   end   return sum end  puts solver(1) 

instead of:

temp = n(n+1) 

put:

temp = n*(n+1) 

Comments

Popular posts from this blog

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -