[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

I need help debugging my program

Icarus Daedalus

12/16/2007 10:48:00 AM

I'm new to Ruby and I'm trying out a very basic user input program. The
codes below and also I've indicated the line giving me grief.

puts "What is your name?"
name = gets.chomp
puts "How old are you?"
age = gets.chomp
age.to_s
puts "What year is it?"
year = gets.chomp
birth = year -= age #*********************************************
puts name + " is " + age + " and was born in " + birth



Any help you could give me would be appreciated. Thanks!
--
Posted via http://www.ruby-....

11 Answers

Sebastian Hungerecker

12/16/2007 11:04:00 AM

0

Icarus Daedalus wrote:
> puts "How old are you?"
> age = gets.chomp
> age.to_s

In this line you're asking ruby to give you a string representation of age.
This is superfluous for two reasons:
a) You're not storing the result anywhere or do anything with it. That's like
if you have a line in your code that just says 2+2 and nothing else. to_s
doesn't modify the receiver it just returns a string. If you don't use the
return value, it does nothing at all.
b) gets always returns a string, so age is a string. Turning a string into a
string is redundant.


> puts "What year is it?"
> year = gets.chomp
> birth = year -= age

Here you're trying to use the String#- method without previously defining it.
By default it's not possible in ruby to subtract strings, which is pretty
sensible, cause what would "bla" - "blubb" even mean?


HTH,
Sebastian
--
NP: Katatonia - For Funerals to Come
Jabber: sepp2k@jabber.org
ICQ: 205544826

T K

12/16/2007 11:11:00 AM

0

What does "birth = year -= age" try to do?

Tek

On Dec 16, 2007, at 7:48 PM, Icarus Daedalus wrote:

> I'm new to Ruby and I'm trying out a very basic user input program.
> The
> codes below and also I've indicated the line giving me grief.
>
> puts "What is your name?"
> name = gets.chomp
> puts "How old are you?"
> age = gets.chomp
> age.to_s
> puts "What year is it?"
> year = gets.chomp
> birth = year -= age #*********************************************
> puts name + " is " + age + " and was born in " + birth


yansimon52

11/16/2013 5:33:00 PM

0

bro....forget abt....who is gonna pay for his crime or their crime.
frm d very very top....like "malchan" viewing planet earth from a space station like tat la...u sare able tok realise this...in tis world....there is " no rights or wrong"...sooo.one just got to do thing or deal wit matter is..by using yr conscience.

TheInquirer

11/16/2013 5:42:00 PM

0

On 11/17/2013 1:32 AM, yansimon52 wrote:
> bro....forget abt....who is gonna pay for his crime or their crime.
> frm d very very top....like "malchan" viewing planet earth from a space station like tat la...u sare able tok realise this...in tis world....there is " no rights or wrong"...sooo.one just got to do thing or deal wit matter is..by using yr conscience.


is it just like a multi-player computer game in Internet cafe just next
door to Heaven ... some people play the "Evil" side, some people play
the "Good" side ...

... after the game is over, then you say to the other
party (e.g. Hitler, Pol Plot) "Hey! that was a good game! It's so real
that I cried! And you acted very well. I really thought you were
really evil!" ... after that kiss, make up, and then have drinks and
beer and potato chips? yes? correct?

baldeagle

11/16/2013 9:03:00 PM

0

On Saturday, 16 November 2013 17:45:58 UTC+8, yansimon52 wrote:
> Halooo botak....long long time no seeeeee.
>

Hi Simoni...
Long, long time no talk.. How are you ?
I was away travelling...visiting old friends and re-visiting places I have been. Friends have grown old and places changed.

> Actually hor...its a right move by d govt not to impose d "death sentence" even on other heinous crime.
> Why i said that?
>
> 1)..ppl who got caught for committng crime...they pay for it wit jail term...for serious case...a life sentence....considered tat these criminal paid their dues.

Hanging drug traffickers is not about crime and punishment...it is about protecting our kids against the drug danger...being killed by overdose, whose future being destroyed by drugs...who turn to crimes to feed their addition.

Until now, Singapore has hardly a drug problem because we hang drug traffickers. If you have been to Chicago, thousands of youth died because of gang wars fighting to control drug sales every year, thousands of youth died because of overdose every year... kids are pushing drugs to feed their drug addiction....and Chicago is suffering huge social problems caused by drug culture. Hanging those who peddle death are the ONLY way to stop drug from getting into Singapore.
We will regret it one day...for being soft on the drug evils...for giving in to human rights activists(NGOs) many of whom work for drug cartel.


>
>
>
> 2) spliritually speaking..those who got caught for murder....its abt a man's that is dictated by his fate....maybe at a wrong place n wrong time..
>
> U tell me...who want to be a "born killer"?
>
>
>
> If the above quotes maybe u dont quite agree.....ok..let quote on those international mass killees..like hitler n pol pot....who killed mlion....n they just died so easily...so who is going to account for theur crime?

Hitler was a war killer so is President Bush who killed almost a million Iraqi including women and infant with the 'shock and awe' war tactics to soften the Iraqi.
Hitler was a devil because he lost the war...if Germany had won, Hitler would be a hero. Western historian and spin doctors created a monster in Hitler but hide Bush killings because he is an American president.

>
> so can say...these mass killers were fated as mass killers n tos million who were murdered were fated to die in d hand of these mass killers.

yansimon52

11/17/2013 3:55:00 AM

0

halooo Botak....in every murder case or drug case.....there is always case that is subjective for aegument. in a Murder case..it could be ...at the wrong place n wrong time....in a drug case " ppl could be made used as mule". We hv seen stories abt ppl were hanged innocently after the real old murderer came out to confess. If such case happened...how to pay back a life?
So...the safest bet n oso base on compassion...its best to hv a life sentence than to kill them(by the authority).A life sentence is good enough to make a human to regret on his past wrong doing. As i said...we all are not " born killsr".
Botak..tis is my take.

baldeagle

11/17/2013 4:54:00 AM

0

On Sunday, 17 November 2013 11:55:17 UTC+8, yansimon52 wrote:
> halooo Botak....in every murder case or drug case.....there is always case that is subjective for aegument.

Murder case...is about crime and punishment. I'm not bothered about how we punished or not punished criminals.

As for DRUG.... it is NOT, NOT, NOT about crime...and NOT about punishment.
As parents and leaders it is our duty to protect the young kids and the innocent. It is our duty to do ALL POSSIBLE to stop the flow of drug into Singapore. Drug KILL our children,... rope them of their future, make our children drug addicts and turn into thieves and cheaters to feed their addiction.. I have seen how drugs ruin the life of thousands American kids, (tens of thousands of young drug addicts in almost every city).

So far, with the death penalty, Singapore is relatively drug free. Once we remove this death penalty, I am concern that Singapore will eventually become a cess pool..with drug dealers, drug addicts, with increased crimes, murders, prostitution....



> in a Murder case..it could be ...at the wrong place n wrong time....in a drug case " ppl could be made used as mule". We hv seen stories abt ppl were hanged innocently after the real old murderer came out to confess. If such case > happened...how to pay back a life?

There is no need to worry about hanging an innocent person.
Until NOW, the police was careful...they know that human life is at stake....they do everything possible to ensure NO innocent was hanged....ALL those hanged were guilty of trafficking.


>
> So...the safest bet n oso base on compassion...its best to hv a life sentence than to kill them(by the authority).A life sentence is good enough to make a human to regret on his past wrong doing. As i said...we all are not " born killsr".
>
> Botak..tis is my take.

yansimon52

11/17/2013 12:17:00 PM

0

Hi Botak....u oso got a point there...cos once a person addicted to drug...its a "gone case" to his family. ....to society..he is a burden to ppl.
Abt 40 yrs ago...back then..."MX". pill was an in-thing. at that time i got few frens who were hooked on MX pills...n ganja. Tat was the moment where i felt useless cos its impossible to help my frens to overcome them frm taking drug. I even came to a situation where i got to buy a coffin to bury my fren cos his parent totally gave up in him.

So i can imagine wat u said abt those pdrug problem face by the western societies where its govt is too relax in dealing wit this drug trafficker.

TheInquirer

11/17/2013 5:45:00 PM

0

On 11/17/2013 8:16 PM, yansimon52 wrote:
> Hi Botak....u oso got a point there...cos once a person addicted to drug...its a "gone case" to his family. ....to society..he is a burden to ppl.
> Abt 40 yrs ago...back then..."MX". pill was an in-thing. at that time i got few frens who were hooked on MX pills...n ganja. Tat was the moment where i felt useless cos its impossible to help my frens to overcome them frm taking drug. I even came to a situation where i got to buy a coffin to bury my fren cos his parent totally gave up in him.
>
> So i can imagine wat u said abt those pdrug problem face by the western societies where its govt is too relax in dealing wit this drug trafficker.


coffee and alcohol are also harmful. why these are not banned?

yansimon52

11/18/2013 6:10:00 AM

0

Botak...if put into law to ban coffee n liqour...like tat hor....its worst than sharia law....hehehe