Ask coding questions

← Back to all posts
adding one to a number
hipstersgo

Hey there! I have been trying to do the below exercise but keep on getting stuck. I can't figure out how to have the program add one to the number... Here is the prompt, and my work is attached! Appreciate the help.

Write a program which asks for a person's favorite number. Have your program add one to the number, then suggest the result as a bigger and better favorite number. (Do be tactful about it, though.)

Voters
hipstersgo
Comments
hotnewtop
bossotron13

Remove line 4 and replace line 5 with this

Zavexeon

@bossotron13 To add on that, var2 = number++ is also valid. ++ is shorthand for + 1.

hipstersgo

Hey there! Thanks for your help, but for some reason, it's still not working! @bossotron13 see above

bossotron13

@hipstersgo i see your issue now, you are trying to add a integer to a string. You need to convert the variable Number to an int. I googled it because i don't know ruby so try adding this before you attempt to add 1 to number

If you find this as the solution press the check mark next to my comment

hipstersgo

@bossotron13 spent a bunch more time with it and finally got it to work! Here you go!

bossotron13

@hipstersgo glad you fixed it but i dont think it should be this complicated, ive never learned ruby so it might be.