Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Sep 26th, 2007, 9:57 AM   #1
ggeo1
Newbie
 
Join Date: Sep 2007
Location: Greece
Posts: 2
Rep Power: 0 ggeo1 is on a distinguished road
split command

Hello, i am a new ruby user and i started reading it the last days.
Generally,i know a few things from C++ .

I wrote a program which gives the amount of a radionuclide remaining after a period of time.I want to use the split command but somewhere i am making a mistake and i don't know where.I am giving you the code:

Quote:
#!/usr/bin/env ruby

puts " Give initial amount in mg,half life time in days and period of time at which to find amount remaining : "
data = gets.to_f
initial_amount,half_life,time = data.split(" ")

initial_amount = initial_amount.to_f
half_life = half_life.to_f
time = time.to_f

amount_remaining = initial_amount * (0.5) ** (time / half_life)
amount_remaining = amount_remaining.to_f

puts " The amount remaining in mg is = "
puts amount_remaining
Thanks
ggeo1 is offline   Reply With Quote
Old Sep 26th, 2007, 10:49 AM   #2
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Quote:
Originally Posted by ggeo1 View Post
data = gets.to_f
initial_amount,half_life,time = data.split(" ")
You can only split a string, not a number. "gets" returns a string, but "to_f" turns it into a number (or to be more exact, a float). Get rid of the "to_f" for this line.
Arevos is offline   Reply With Quote
Old Sep 26th, 2007, 11:03 AM   #3
ggeo1
Newbie
 
Join Date: Sep 2007
Location: Greece
Posts: 2
Rep Power: 0 ggeo1 is on a distinguished road
OK!

Thanks!

It worked!
ggeo1 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Command Prompt SkyPioneer Coder's Corner Lounge 5 May 3rd, 2006 10:07 PM
Need help coming up with mnemonic for command processing aznluvsmc Bash / Shell Scripting 6 Feb 21st, 2006 5:56 PM
A simple script to execute a command package satimis Bash / Shell Scripting 3 Aug 12th, 2005 11:28 PM
system () command in Borland C++ Bldr. 4 L7Sqr C++ 14 Jun 18th, 2005 8:15 PM
Win32 execution of a Command Line program hemanth.balaji C++ 7 May 20th, 2005 9:14 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:46 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC