Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9246491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:30:07+00:00 2026-06-18T09:30:07+00:00

I am creating a program that accepts ten numbers from a user. Then, it

  • 0

I am creating a program that accepts ten numbers from a user. Then, it displays the total of the ten numbers, their average, and the smallest and largest numbers. Finally, it is supposed to display the word ‘Jackpot!’ for every number entered that is of the same or greater value than 100, and ‘Tough Luck.’ for every number less than 100.

My code does not seem to be working and will not run in Ruby.

puts 'Please enter 10 numbers one at a time.' 
num1=gets.chomp
num2=gets.chomp
num3=gets.chomp
num4=gets.chomp
num5=gets.chomp
num6=gets.chomp 
num7=gets.chomp
num8=gets.chomp
num9=gets.chomp
num10=gets.chomp
value_list=[num1, num2, num3, num4, num5, num6, num7, num8, num9, num10] 
subtotal=0
for x in 0..9
subtotal=subtotal+value_list[x]
puts 'Total: ' + subtotal
average=subtotal/10.to_f
average=sprintf("%.2f",average)
puts 'Average: ' + average
puts 'Smallest value: ' + sprintf("%.2f",value_list.min.to_s)
puts 'Largest value: ' + sprintf("%.2f",value_list.min.to_s)
if num1..num10 >=100
puts 'Jackpot!'
else
puts 'Tough Luck.'
sleep 120
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T09:30:08+00:00Added an answer on June 18, 2026 at 9:30 am

    A few things:

    1. You need to end your blocks: for ... end, if ... else ... end, etc. This is the main reason it won’t run, i.e. the parser doesn’t recognize it as valid syntax.

    2. gets.chomp returns a string, but you are looking for integers. Try gets.chomp.to_i to force integer types.

    3. 'Total: ' + subtotal: you would be adding an integer to a string, which is not allowed. Ruby string interpolation goes like this (double quotes required): "Total: #{subtotal}". This will transform the subtotal variable into a string and insert it into the other string on the fly.

    4. I’m not sure what you’re trying to do here: if num1..num10 >= 100. Is this if any member of the range is greater than 100, or if the sum is greater than 100?

    There’s also a lot of optimization you can do here. One good opportunity is when you have a lot of repeated code, as in num1 = gets.chomp.to_i; num2 = gets ... etc.

    Here’s a version of your program that (I think) does what you want it to. If you’re serious about learning Ruby, go look up the documentation for some of these methods (<<, inject, .times etc):

    puts 'Please enter 10 numbers one at a time.' 
    value_list = []
    10.times do
      value_list << gets.chomp.to_i
    end
    
    subtotal = value_list.inject(:+)
    
    puts "Total: #{subtotal}"
    puts "Average: #{(subtotal/10.0).round(2)}"
    puts "Smallest value: #{value_list.min}"
    puts "Largest value: #{value_list.max}" 
    
    if subtotal >= 100
      puts 'Jackpot!'
    else
      puts 'Tough Luck.'
    end
    

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Bassicly im creating a program that reads information from an xml file into a
I'm creating a program that authenticates from a before it runs. I also want
I am creating a program that allows the user to select a drive letter
I am creating a program that displays several bases and the amount of troops
Im creating a program that prints out the Ip adress of the User. So
I'm creating a program that will do a user-predefined number of tasks, say, 100.
I'm creating a program that allow a user introduce a lambda function only writing
I am creating a program that will download a .jar (java) file from a
i'm having problems creating a program that converts a string of numbers into an
I am creating a program that displays a popup at certain times (just like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.