From ae8c4439027d59e17e24c3cbbc9c98ad0934fa47 Mon Sep 17 00:00:00 2001 From: Chris M Date: Thu, 16 Jan 2020 11:25:41 -0800 Subject: [PATCH] Feedback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Note** This is not a gist, so I had to make a pull request to give you feedback. Take a look at my suggested changes in the other tab. # Candy Machine | Requirement | Comments |---|--- | Well formatted code | Good space breaks between sections, but you didn't indent at all, see my changes above | Prompts for the amount of money | 👍 | Displays candy options and reads in user select | 👍 | Determines if the user can afford it | Mostly yes | Calculates the user's change | ⚠️ It gives me negative change if I have $0.50 and order a twix | `Optional` Handle when the buyer enters "C" or "c" so that it works as expected | NA | `Optional` Do something appropriate when the buyer enters an invalid amount for the money and an invalid selection | NA ## Summary Not bad, things to work on include testing the app more throughly with different amounts of money and improving your code formatting to make it more readable. --- cm00.rb | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/cm00.rb b/cm00.rb index fb5fbcf..645a443 100644 --- a/cm00.rb +++ b/cm00.rb @@ -7,11 +7,12 @@ puts "(All candy provided is virtual.)" print "How much money do ya got? > $" -m = gets.chomp.to_f #prompting user for input +money = gets.chomp.to_f #prompting user for input -puts "$#{m} that's all?" +puts "$#{money} that's all?" puts "Well, lemme tell ya what we got here." puts "" + choices = Hash.new() #creating a new hash choices["a"] = 0.65 #adding to my hash choices["b"] = 0.50 @@ -27,15 +28,15 @@ puts "E $0.55 Juicy Fruit Gum" puts "" puts "So, What'll ya have? >" #prompting user to choose -choice= gets.chomp.downcase +choice = gets.chomp.downcase #if statement basically checks if the amount of money is more than the candy choice that got picked -if m >= choices["a"] || m >= choices["b"] || m >= choices["c"] || m >= choices["d"] || m >= choices["e"] -puts "Thanks for purchasing candy through us." -puts "Please take your candy, and your $#{m-choices[choice]} change!" +if money >= choices["a"] || money >= choices["b"] || money >= choices["c"] || money >= choices["d"] || money >= choices["e"] + puts "Thanks for purchasing candy through us." + puts "Please take your candy, and your $#{money-choices[choice]} change!" #if money is less than the choice else -puts "You're broke. Take your $#{m} and go elsewhere." + puts "You're broke. Take your $#{money} and go elsewhere." end