Name: Anonymous 2012-10-31 16:38
ok, so im trying to learn ruby the same way i learn everything else. redo all my 1st year CS homework. is ruby really so stupid that i have to declare 'shit' as a global var for it to be used as an exit for this loop? or am i completely retarded and missing something>?
@shit = 1 #FOR ALL THAT IS FUCKING HOLY
#when doing a while loop, you must use '@' infront of a variable
#to make it global. meaning if you want to use mc, dec, ec, et or any other
#vars inside the while loop, you would have to make them global as well.
#but this doesnt make sence because none of the examples online are like this.
while @shit == 1
mc = 8.5
dec = 9.75
wc = 10.5
et = 12.5
puts "How many milk chocolate"
mcq = gets.to_f
puts "How many Dark Euro Chocolate?"
decq = gets.to_f
puts "how many white chocolate?"
wcq = gets.to_f
puts "how many euro truffles?"
etq = gets.to_f
mct = mcq * mc
dect = dec *decq
wct = wcq * wc
ett = et * etq
subtotal = mct+dect+wct+ett
if subtotal >= 20 or subtotal <= 39.99
discount = subtotal * 0.10
elsif subtotal >= 40 or subtotal <= 59.99
discount = subtotal * 0.15
elsif subtotal >= 60 or subtotal <= 79.99
discount = subtotal * 0.20
elsif subtotal >= 80
discount = subtotal * 0.25
end
subtotalstr = subtotal.to_s
discountstr = discount.to_s
puts "Subtotal = " + subtotalstr
if subtotal >= 20
adjsub = subtotal - discount
puts "discount = " + discountstr
adjsubstr = adjsub.to_s
puts "adjusted subtotal = " + adjsubstr
end
puts "Order another? 1/2"
@shit = gets.to_i
if @shit != 1
@shit = 2
end
end