This question does not apply to a Codecademy exercise - it's from an external source of small exercises I've been playing around with. If that's against the rules I do apologise (although I'm pretty sure it isn't:
"Use these forums to connect with other users and talk about your journey of learning how to code (either on Codecademy or outside of it)"
First off, this is probably going to come across as a really newb question to a lot of you, but please understand I only started learning anything related to Ruby and programming yesterday.
So I'm working on an exercise where I need to do the following:
"Write a program that asks the user three simple sums. Each sum should ask the user to multiply two random numbers, between one and ten. The program should keep score of how many questions the user got correct, and display the score at the end. Your program must contain a while loop that loops three times. The output for your program should look something like this:
>>>>>>>>>> Running: game.rb >>>>>>>>>>>>>>>
Welcome to Super Multiplier!
What is 1 times 7?
What is 2 times 6?
What is 3 times 6?
Thank you for playing!
You scored 2 out of 3
<<<<<<<<<< Finished successfully <<<<<<<<<<"
So great, I've managed to do everything except generate a score (yay you got 2 out of 3 or whatever) and I've been staring at it all day. I've used "correct" as a variable because I suppose I'll be able to find a way to generate a score more easily that way. Anything else that seems unnecessarily cumbersome is just me being new and stupid. Here's what I've done:
puts() puts() puts("Welcome to Super Multiplier!") puts("===================================") puts() i = 0 while i < 3 puts() i = i + 1 x = (rand(10)) y = (rand(10)) z = x * y puts(("What is ") + String(x) + " times " + String(y) + ("?")) answer = Integer(gets()) correct = "Correct!" incorrect = "Incorrect." if answer == z puts(correct) else puts(incorrect) end end puts() puts("Thank you for playing!") puts("You scored ??? out of " + String(i) + ".") puts()
Can someone please put me out of my misery? I want to get on with other exercises.
Thanks in advance!