The quick answer would be because when you input $c it includes the newline
character.  You need to "chomp" it off, so add this to your script:

chomp $c;

Shane


On Mon, Oct 25, 2010 at 10:35 AM, saran <simssa...@gmail.com> wrote:

> i am new to perl. please help me with this piece of code below.
> answer wat it prints is correct but the format has to adjusted...!
> program to convert Celsius to Fahrenheit
>
> **********************************************************************************
> #!/usr/bin/perl
> use warnings;
> use strict;
>
> print "Celsius to Fahrenheit Conversion\n";
> print "Enter the value of Celsius to be converted:";
>
> my $c = <STDIN>;
> my $f = ($c*1.8) + 32;
> print "$c"."C is equal to ", "$f","F","\n"
>
> ***************************************************************************
> Output
>
> Celsius to Fahrenheit Conversion
> Enter the value of Celsius to be converted:40
> 40
> C is equal to 104F
> *************************************************************************
>
> why does "C is equal to 104F" prints on a new line rather than "40 C
> is equal to 104F"
> on a single line...
> please help
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>

Reply via email to