0 Replies - 249 Views - Last Post: 26 July 2007 - 09:21 AM

#1 PennyBoki   User is offline

  • D.I.C Lover
  • member icon

Reputation: 55
  • View blog
  • Posts: 2,345
  • Joined: 11-December 06

Conversion into Bytes

Posted 26 July 2007 - 09:21 AM

Description: Just copy the code and run it in a Ruby InterpreterThis program converts kilobytes, megabytes, gigabytes into bytes.
#PennyBoki @ 
puts '_______Conversion into Bytes_______'
puts 'Enter'
puts 'K for Kilobytes'
puts 'M for Megabytes'
puts 'G for Gigabytes'
STDOUT.flush
ch = gets.chomp
puts 'Now enter a value:' 
STDOUT.flush
val = gets.chomp
if ch == 'K'
  x = val.to_i*1024
  puts ''+val.to_s+' Kylobytes = '+x.to_s+' Bytes'
elsif ch == 'M' 
  x = val.to_i*1024*1024
  puts ''+val.to_s+' Megabytes = '+x.to_s+' Bytes'
    elsif ch == 'G' 
  x = val.to_i*1024*1024*1024
  puts ''+val.to_s+' Gigabytes = '+x.to_s+' Bytes'
  else puts 'Invalid input.'
end



Is This A Good Question/Topic? 0
  • +

Page 1 of 1