Class: InflationCalc

Inherits:
Object
  • Object
show all
Defined in:
lib/inflation-calc.rb

Instance Method Summary collapse

Instance Method Details

#calculateObject



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/inflation-calc.rb', line 111

def calculate
	print "Enter amount: "
	amount = gets.chomp
	print "Pick a year from 1913 to 2013: "
	year = gets.chomp.to_i
	while true
		if year < 1913 || year > 2013
			print "The year must be from 1913 to 2013. Enter year: "
			year = gets.chomp.to_i
		else
			break
		end
	end
	a = amount.to_d * (cpi[2014].to_d / cpi[year].to_d)
	puts "$#{amount} in #{year} has the same buying power as $#{a.to_f.round(2)} in 2014."

end

#cpiObject

data from the Bureau of Labor Statistics



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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/inflation-calc.rb', line 6

def cpi
	cpi = {1913 => 9.9,
	1914 => 10,
	1915 => 10.1,
	1916 => 10.9,
	1917 => 12.8,
	1918 => 15.1,
	1919 => 17.3,
	1920 => 20,
	1921 => 17.9,
	1922 => 16.8,
	1923 => 17.1,
	1924 => 17.1,
	1925 => 17.5,
	1926 => 17.7,
	1927 => 17.4,
	1928 => 17.1,
	1929 => 17.1,
	1930 => 16.7,
	1931 => 15.2,
	1932 => 13.7,
	1933 => 13,
	1934 => 13.4,
	1935 => 13.7,
	1936 => 13.9,
	1937 => 14.4,
	1938 => 14.1,
	1939 => 13.9,
	1940 => 14,
	1941 => 14.7,
	1942 => 16.3,
	1943 => 17.3,
	1944 => 17.6,
	1945 => 18,
	1946 => 19.5,
	1947 => 22.3,
	1948 => 24.1,
	1949 => 23.8,
	1950 => 24.1,
	1951 => 26,
	1952 => 26.5,
	1953 => 26.7,
	1954 => 26.9,
	1955 => 26.8,
	1956 => 27.2,
	1957 => 28.1,
	1958 => 28.9,
	1959 => 29.1,
	1960 => 29.6,
	1961 => 29.9,
	1962 => 30.2,
	1963 => 30.6,
	1964 => 31,
	1965 => 31.5,
	1966 => 32.4,
	1967 => 33.4,
	1968 => 34.8,
	1969 => 36.7,
	1970 => 38.8,
	1971 => 40.5,
	1972 => 41.8,
	1973 => 44.4,
	1974 => 49.3,
	1975 => 53.8,
	1976 => 56.9,
	1977 => 60.6,
	1978 => 65.2,
	1979 => 72.6,
	1980 => 82.4,
	1981 => 90.9,
	1982 => 96.5,
	1983 => 99.6,
	1984 => 103.9,
	1985 => 107.6,
	1986 => 109.6,
	1987 => 113.6,
	1988 => 118.3,
	1989 => 124,
	1990 => 130.7,
	1991 => 136.2,
	1992 => 140.3,
	1993 => 144.5,
	1994 => 148.2,
	1995 => 152.4,
	1996 => 156.9,
	1997 => 160.5,
	1998 => 163,
	1999 => 166.6,
	2000 => 172.2,
	2001 => 177.1,
	2002 => 179.9,
	2003 => 184,
	2004 => 188.9,
	2005 => 195.3,
	2006 => 201.6,
	2007 => 207.342,
	2008 => 215.303,
	2009 => 214.537,
	2010 => 218.056,
	2011 => 224.939,
	2012 => 229.594,
	2013 => 232.957,
	2014 => 233.916}
end