Helo Saran,

The reason why it was printed in the next line is because u have no used
chomp function on $c.Chomp would remove unwanted new line characters.
I added chomp($c) to ur code and it works fine.. i mean as hw u wanted..
pls find the same code below with chomp..
#######################################
#!/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>;
chomp($c);
my $sf = ($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
40C is equal to 104F
~~~~~~~~~~~~~~~~

Hope this helps...

Regards
Ashwin Thayyullathil Surendran
#91 9884444732


On Mon, Oct 25, 2010 at 9:51 PM, 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