-
Notifications
You must be signed in to change notification settings - Fork 49
Create calculator.rb #47
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?
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,49 @@ | ||||||||
|
|
||||||||
|
|
||||||||
| puts "Welcome to the operator program! which operator would you like to use?" | ||||||||
|
|
||||||||
| operatormenu =["add(+)","subtract(-)","multiply(*)","divide(/)"] | ||||||||
|
|
||||||||
| def printmenu(arr) | ||||||||
| 4.times do |i| | ||||||||
| puts "#{i+1}. #{arr[i]}" | ||||||||
| end | ||||||||
| end | ||||||||
|
|
||||||||
| printmenu(operatormenu) | ||||||||
|
|
||||||||
| puts "which operation would you like to carry on?" | ||||||||
| x = gets.chomp | ||||||||
| options = ["add", "+","subtract","-","multiply","*","divide","/"] | ||||||||
| if !options.include?(x) | ||||||||
| puts "wrong input! try again!" | ||||||||
| x = gets.chomp | ||||||||
|
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. indentation |
||||||||
| end | ||||||||
|
|
||||||||
|
|
||||||||
| puts "what numbers would you like to calculate" | ||||||||
| a= gets.chomp.to_i | ||||||||
|
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. Don't use variable names like |
||||||||
| while !options.include?(a==Integer) | ||||||||
|
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. This doesn't work.
Suggested change
|
||||||||
| puts "wrong input! Please enter an Integer .. try again!" | ||||||||
| a=gets.chomp.to_i | ||||||||
| end | ||||||||
| b= gets.chomp.to_i | ||||||||
| while !options.include?(b==Integer) | ||||||||
|
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.
Suggested change
|
||||||||
| puts "wrong input! Please enter an Integer .. try again!" | ||||||||
|
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.
Suggested change
|
||||||||
| end | ||||||||
|
|
||||||||
| def operator(m,n,y) | ||||||||
| case y | ||||||||
|
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. The |
||||||||
| 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. The |
||||||||
| return "the result is #{m+n}" | ||||||||
| when "subtract","-" | ||||||||
| return "the result is #{m-n}" | ||||||||
| when "multiply","*" | ||||||||
| return "the resutl is #{m*n}" | ||||||||
| when "divide","/" | ||||||||
| return "the result is #{m/n}" | ||||||||
| end | ||||||||
| end | ||||||||
|
|
||||||||
| puts operator(a,b,x) | ||||||||
|
|
||||||||
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.
Indentation is needed here.