Skip to content
Sign upLog in
← Back to Community

adding one to a number

Profile icon
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.)

Screen Shot 2020-01-27 at 8.19.14 AM

Voters
Profile icon
MichaelaMary
Profile icon
hipstersgo
Comments
hotnewtop
Profile icon
bossotron13

Remove line 4 and replace line 5 with this

var2 = number + 1
Profile icon
Zavexeon

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

Profile icon
hipstersgo

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

@bossotron13
see above

Profile icon
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

Integer(number) *somecode* var2 = number + 1

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

Profile icon
hipstersgo

@bossotron13
spent a bunch more time with it and finally got it to work! Here you go!
Screen Shot 2020-02-01 at 1.10.09 PM

Profile icon
bossotron13

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