From 843ff6d83c391c759f68fe4f17612b3f5826ed30 Mon Sep 17 00:00:00 2001 From: Aruna Date: Mon, 5 Feb 2018 22:53:44 -0800 Subject: [PATCH 1/3] Aruna --- menu.rb | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 menu.rb diff --git a/menu.rb b/menu.rb new file mode 100644 index 0000000..6b1fb00 --- /dev/null +++ b/menu.rb @@ -0,0 +1,50 @@ +# Program to print the random Menu + +#adjectives = [ "hot","sour","crunchy","smooth","spicy","sweet","salty","creamy","dry","soft"] +#cooking_styles = ["fried","baked","steamed","smoked","sauted","charboiled","mexican","chinese","thai","cooked"] +#foods = ["cake","dumplings","tacos","beans","burrito","pizza","clam","pasta","rice","noodles"] + +# To print a user generated random menu +# Array for storing adjectives +adjectives_array = Array.new +# Array for storing cookinf cooking styles +cookingstyle_array = Array.new +# Array for storing foods_rand +foods_array = Array.new +# user input to have number of items in the menu +print " Number of items in the menu " +no_of_items = gets.chomp.to_i + +# prompting for user input to generate menu items +no_of_items.times do + print " Enter the adjectives of the menu:\t" + adjectives = gets.chomp + adjectives_array.push(adjectives) + print " Enter the cooking_style of the menu:\t " + cookingstyle = gets.chomp + cookingstyle_array.push(cookingstyle) + print " Enter the foods u want in the menu:\t" + foods = gets.chomp + foods_array.push(foods) +end + +menucount = no_of_items - 1 +print "How many items do you want to see in menu : " +items_to_display = gets.chomp.to_i +# To check whether user-chosen number of items is not larger than the number of items we have in arrays. +if items_to_display < no_of_items + +# To select the menu items randomly + no_of_items.times do |i| + adj_rand = rand(0..menucount) + cook_rand = rand(0..menucount) + foods_rand = rand(0..menucount) + print " #{i+1}. #{adjectives_array[adj_rand]} #{ cookingstyle_array[cook_rand]} #{foods_array[foods_rand]}\n " + menucount = menucount-1 + # To ensure that no descriptive term in a menu item is ever repeated + adjectives_array.delete_at(adj_rand) + cookingstyle_array.delete_at(cook_rand) + foods_array.delete_at(foods_rand) + end +else print " Items you want to display are more than what we have in the menu " +end From a1db7230667c59987da4a7196a5c8815ed38fec2 Mon Sep 17 00:00:00 2001 From: aruna79 <35058606+aruna79@users.noreply.github.com> Date: Mon, 5 Feb 2018 23:01:23 -0800 Subject: [PATCH 2/3] Update menu.rb --- menu.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/menu.rb b/menu.rb index 6b1fb00..06cd7e5 100644 --- a/menu.rb +++ b/menu.rb @@ -1,9 +1,5 @@ # Program to print the random Menu -#adjectives = [ "hot","sour","crunchy","smooth","spicy","sweet","salty","creamy","dry","soft"] -#cooking_styles = ["fried","baked","steamed","smoked","sauted","charboiled","mexican","chinese","thai","cooked"] -#foods = ["cake","dumplings","tacos","beans","burrito","pizza","clam","pasta","rice","noodles"] - # To print a user generated random menu # Array for storing adjectives adjectives_array = Array.new From e2f0297d4dff8e81f0e5a10cfd3ab9bb5d8e5eb8 Mon Sep 17 00:00:00 2001 From: aruna79 <35058606+aruna79@users.noreply.github.com> Date: Wed, 7 Feb 2018 22:50:32 -0800 Subject: [PATCH 3/3] Update menu.rb --- menu.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/menu.rb b/menu.rb index 06cd7e5..d05293c 100644 --- a/menu.rb +++ b/menu.rb @@ -24,7 +24,7 @@ foods_array.push(foods) end -menucount = no_of_items - 1 +menu_index = no_of_items - 1 print "How many items do you want to see in menu : " items_to_display = gets.chomp.to_i # To check whether user-chosen number of items is not larger than the number of items we have in arrays. @@ -32,11 +32,11 @@ # To select the menu items randomly no_of_items.times do |i| - adj_rand = rand(0..menucount) - cook_rand = rand(0..menucount) - foods_rand = rand(0..menucount) + adj_rand = rand(0..menu_index) + cook_rand = rand(0..menu_index) + foods_rand = rand(0..menu_index) print " #{i+1}. #{adjectives_array[adj_rand]} #{ cookingstyle_array[cook_rand]} #{foods_array[foods_rand]}\n " - menucount = menucount-1 + menu_index = menu_index-1 # To ensure that no descriptive term in a menu item is ever repeated adjectives_array.delete_at(adj_rand) cookingstyle_array.delete_at(cook_rand)