forked from AdaGold/random-menu
-
Notifications
You must be signed in to change notification settings - Fork 25
Create random-menu.rb #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tfrego
wants to merge
1
commit into
Ada-C10:master
Choose a base branch
from
tfrego:patch-1
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| 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 | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.