-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalc_ch4.rb
More file actions
47 lines (39 loc) · 837 Bytes
/
calc_ch4.rb
File metadata and controls
47 lines (39 loc) · 837 Bytes
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
#var 1 = 2
#var 2 = '5'
#puts var1 + var2
#returns ERROR
#conversion to a string
var1 = 2
var2 = '5'
puts var1.to_s + var2
#conversion to an integer
puts var1 + var2.to_i
#more conversions (float, strings, integers)
puts '15'.to_f
puts '99.999'.to_f
puts '99.999'.to_i
puts ''
puts '5 is my favorite number!'.to_i
puts 'Who asked you about 5 or whatever?'.to_i
puts 'Your momma did. '.to_f
puts ''
puts 'string'.to_s
puts 3.to_i
puts 20
puts 20.to_s
puts '20'
var20 = 20.to_s
var21 = 20.to_f
var22 = 20.to_i
puts var20 + ' is a string'
puts var20 * 5
puts var21 * 5
puts var22 * 5
#name input and response
#puts 'Hello there! What\'s your name?'
#name = gets
#puts 'Well hello there, ' + name +'.'
#name input and response with CHOMP
puts 'Hello there! What\'s your name?'
name = gets.chomp
puts 'Well hello there, ' + name +'.'