-
Notifications
You must be signed in to change notification settings - Fork 0
/
basiccalc.rb
62 lines (50 loc) · 1.49 KB
/
basiccalc.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#Calculator Pseudocode
puts "Welcome to Calculator Program"
puts "Enter Number, then operator(+,-,*,/), then the second number"
print "Please input your first number: "
entry_1 = gets.to_i
puts "You entered #{entry_1}"
#get an operator from the user (+-/*)
#puts "Please select the operation you want to perform:"
puts "For additon, type '1' For Subtraction, type '2'"
puts "To Multiply, type '3' For Division, type '4'"
print "Type selection now: "
entry_2 = gets.to_i
operationarr = ["why did you put 0?","+", "-", "*", "/"]
operation = operationarr[entry_2]
puts "You selected #{operation}"
print "Please input your second number: "
entry_3 = gets.to_i
puts "You entered #{entry_3}"
#Get a number from the user
if entry_2 == 1
result_1 = entry_1 + entry_3
#operation = operationarr[0]
elsif entry_2 == 2
result_1 = entry_1 - entry_3
#operation = operationarr[1]
elsif entry_2 == 3
#operation = operationarr[2]
result_1 = entry_1 * entry_3
elsif entry_2 == 4
#operation = operationarr[3]
result_1 = entry_1 / entry_3
remainder_1 = entry_1 % entry_3
#
else
puts "Invalid Selection"
end
#puts "You selected #{operation}"
puts " #{entry_1} #{operation} #{entry_3} = #{result_1} "
puts "#{remainder_1}"
#puts "#{result_1}"
#get a second number from the user
#Make calculation
#puts "#{operation}"
#result_1 = entry_1 entry_3
#puts "#{result_1}"
#Display/output result
#Bonuses
#- Make Calculator Loop
#- allow sq, sq root, etc
#- allow result value to be used in next calculation