Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions random-menu.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
puts "Welcome to the Random Menu Generator Program."

# prompts user for how many menu items to display
print "How many menu items would you like to see? "
number_items = gets.chomp.to_i

# array containing food adjectives
adj = []

# array containing food preparation style_numbers
style = []

# array containing food items
food = []

number_items.times do
print "Please provide an adjective: "
adj << gets.chomp
print "Please provide a food preparation style: "
style << gets.chomp
print "Please provide a food: "
food << gets.chomp
end

# # array containing 10 food adjectives
# adj = ["hot", "cold", "spicy", "creamy", "tangy", "salty", "sweet",
# "icy", "sour", "savory"]
#
# # array containing food preparation styles
# style = ["fried", "steamed", "sauteed", "baked", "grilled", "seared",
# "blackened", "herbed", "crusted", "pan-fried"]
#
# # array containing food items
# food = ["chicken", "steak", "pork tenderloin", "salmon", "cod", "halibut",
# "pork chops", "tacos", "noodles", "sausage"]

# array containing random numbers generated
adj_numbers = []
style_numbers = []
food_numbers = []

# randomly generate numbers for each menu item and print to screen
number_items.times do |menu_item|
# generate random number for food adjective
random_adj = rand(0...number_items)
# generate new randon number if adjective has already been used
while adj_numbers.include?(random_adj)
random_adj = rand(0...number_items)
end
# push random number to adj_numbers array
adj_numbers << random_adj
# assign adjective from array to adjective variable
adjective = adj[random_adj]
# generate random number for food preparation style
random_style = rand(0...number_items)
# generate new randon number if adjective has already been used
while style_numbers.include?(random_style)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This loop could theoretically go a very long time until a style not chosen before is selected. It is a potential performance issue.

Not a problem here, but you probably don't want to replicate this solution in other projects.

random_style = rand(0...number_items)
end
# push random number to style_numbers array
style_numbers << random_style
# assign style from array to preparation variable
preparation = style[random_style]
# generate new random number if style has already been used
random_food = rand(0...number_items)
while food_numbers.include?(random_food)
random_food = rand(0...number_items)
end
# push random number to food_numbers array
food_numbers << random_food
# assign food from array to item variable
item = food[random_food]
# print menu item
puts "#{menu_item + 1}. #{adjective} #{preparation} #{item}"
end