-
Notifications
You must be signed in to change notification settings - Fork 49
Space - Faezeh #44
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
base: master
Are you sure you want to change the base?
Space - Faezeh #44
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| # When a user runs this program, the program should ask the user for the following things: | ||
|
|
||
| # 1- a math operation | ||
| # 2- a number for the math operation | ||
| # 3- a second number for the math operation | ||
|
|
||
| puts "I am glad you chose my calculator, because it's awesome! | ||
| Which operator woudl you like to use? | ||
| 1. add(+) | ||
| 2. subtract(-) | ||
| 3. multiply(*) | ||
| 4. divide (/) | ||
| Please choose one operator (name or symbol)" | ||
|
|
||
| command = gets.chomp.downcase | ||
|
|
||
| # operators = ["add", "+", "subtract", "-", | ||
| # "multiply", "*", "devide", "/"] | ||
|
|
||
| # operators.each do |i| | ||
| # puts i + "(" #{i+1} + ")" | ||
| # end | ||
|
|
||
| until ["add", "+", "subtract", "-", "multiply", "*", "divide", "/", ].include?(command) | ||
| puts "What you entered is not an option! | ||
| Please tell me to add (+), subtract (-) multiply (*) or devide (/)!" | ||
| command = gets.chomp.downcase | ||
| end | ||
|
|
||
| class Object | ||
| def is_number? | ||
| to_f.to_s == to_s || to_i.to_s == to_s | ||
| end | ||
| end | ||
|
|
||
| num_1_str = "first" | ||
| until num_1_str.is_number? | ||
| puts "Please provide your first number:" | ||
| num_1_str = gets.chomp | ||
| end | ||
| num_1 = num_1_str.to_f | ||
|
|
||
| num_2_str = "second" | ||
| until num_2_str.is_number? | ||
| puts "Please provide your second number:" | ||
| num_2_str = gets.chomp | ||
| end | ||
| num_2 = num_2_str.to_f | ||
|
|
||
| case command | ||
| when "add", "+" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Really the
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Chris, it seems that I have installed an add on on VS code that is supposed to fix all the indentations when I save the file, but in this case it un-indents the "when" blocks. Is there a way I can fix this? |
||
| puts "We're adding numbers" | ||
| puts "#{num_1} + #{num_2}: #{num_1 + num_2}" | ||
| when "subtract", "-" | ||
| puts "We're subtracting numbers" | ||
| puts "#{num_1} - #{num_2}: #{num_1 - num_2}" | ||
| when "multiply", "*" | ||
| puts "We're multiplying numbers" | ||
| puts "#{num_1} * #{num_2}: #{num_1 * num_2}" | ||
| when "divide", "/" | ||
| puts "We're dividing numbers" | ||
| puts "#{num_1} / #{num_2}: #{num_1 / num_2}" | ||
| end | ||
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.
Clever. Did you find this on Stack Overflow or someplace. It's best to leave a comment with a link to where you find something like this.
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.
I had found it from stack overflow when I was writing code for the technical challenge. I will comment the source from now on when I find something. thank you for reminding me.