Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

first ruby program

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

Name: Anonymous 2012-10-31 17:07

ew, Ruby is so ugly

Name: Anonymous 2012-10-31 18:46

learn haskell instead

Name: Anonymous 2012-10-31 18:51

>>2
i could've put more indents or something i guess.

>>3
well, im on a trip to learn javascript, php, python and ruby. i live in the bay area and its easy to find jobs with wizard level knowledge of those languages. so thats what i doing.

Name: Anonymous 2012-10-31 19:11

just pick one backend language you stupid niggar. no one cares how many languages you know, they want to see shit that you have made.

Name: Anonymous 2012-10-31 19:25

>>5
no.

Don't change these.
Name: Email:
Entire Thread Thread List