#!/usr/bin/perl -w # lab #6 solution #---------------------------------------------------------------------- # 5. Asks the user to input a temperature in degrees Fahrenheit and return it # in all three scales using the subroutines you created. print "Please enter a temperature in degrees Fahrenheit: "; chomp($temp = <STDIN>); $tempC = &FtoC($temp); $tempK = &CtoK($tempC); # 6. Asks the user to input the wind speed in mph. Calculate the wind chill # using the subroutine you created and print the windchill in all three # temperature scales using the conversion subroutines you created. print "Please enter the wind speed in mph: "; chomp($windvel = <STDIN>); $windchill = &WindChill($temp, $windvel); $windchillC = &FtoC($windchill); $windchillK = &CtoK($windchillC); # 7. Print the values to the terminal with some descriptive text. print "The temperature entered was $temp F, $tempC Celcius or $tempK Kelvin\n"; print "The windchill is $windchill F, $windchillC Celcius or $windchillK Kelvin]\n"; exit; # subroutines below... #---------------------------------------------------------------------- sub FtoC { # 1. Create a subroutine that takes the temperature in degrees Fahrenheit as # an argument and returns it in degrees Celcius. my $tempf = $_[0]; my $tempc = ($tempf - 32)/1.8; $tempc = sprintf("%0.2f", $tempc); # format the output return($tempc); } #---------------------------------------------------------------------- sub CtoK { # 2. Create a subroutine that takes the temperature in degrees Celcius as an # argument and returns it in degrees Kelvin. my $tempc = $_[0]; my $tempk = $tempc + 273.15; $tempk = sprintf("%0.2f", $tempk); # format the output return($tempk); } #---------------------------------------------------------------------- sub CtoF { # 3. Create a subroutine that takes the temperature in degrees Celcius as # an argument and returns it in degrees Fahrenheit. my $tempc = $_[0]; my $tempf = ($tempc * 1.8) + 32; $tempf = sprintf("%0.2f", $tempf); # format the output return($tempf); } #---------------------------------------------------------------------- sub WindChill { # 4. Create a subroutine that takes the temperature in degrees Fahrenheit # and the wind speed in mph as arguments and returns the windchill in # degrees Fahrenheit. my $temp = $_[0]; # temperature in degrees fahrenheit my $wind = $_[1]; # wind speed in mph my $wchill = 35.74 + 0.6215 * $temp - 35.75 * $wind ** 0.16 + 0.4275 * $temp * $wind ** 0.16; $wchill = sprintf("%0.2f", $wchill); # format the output return($wchill); }