Lesson 7, Part 5, Temperature Problem

You have been asked to write a computer program for the weather service.  They have two weather stations that report their temperature readings throughout the day.  One of the stations is Alaska and provides their readings in Fahrenheit while the other weather station is Greenland and it provides their readings in Celsius.  They capture the temperatures from 8am EST for a 24 hours period then start all over again.  Each station will let you know when they have given you their last reading for the period (just prior to 8am when the day starts all over again).  After the last temperature of the 24 hour period is reported then they want you to produce the following information.  The highest, lowest and average temperature for each station (given in Fahrenheit for Alaska and Celsius for Greenland).  The highest, lowest and average temperatures overall (given in Fahrenheit).

The following is the conversion calculations:

Fahrenheit to Celsius:
(5/9)*( Tempfahrenheit -32)

Celsius to Fahrenheit
(9/5)* TempCelsius+ 32

 

First Let's do the problem statement for this:
Assumptions
Input
Calculations
Output
Answer

Practice data:

Alaska

Greenland

60

55

50

40

40

10

70

0

20

15

90

28

10

45

60

60

20

15

Output will be:
High Greenland Temperature is 60
Low Greenland Temperature is 0
Average Greenland Temperature is 29.7777777777778
High Alaska Temperature is 90
Low Alaska Temperature is 10
Average Alaska Temperature is 46.6666666666667
High Temperature is 140
Low Temperature is 10
Average Temperature is 66.1333333333333

 

 

 

 

 

 

 

You have been asked to write a computer program for the weather service.  They have two weather stations that report their temperature readings throughout the day.  One of the stations is Alaska and provides their readings in Fahrenheit while the other weather station is Greenland and it provides their readings in Celsius.  They capture the temperatures from 8am EST for a 24 hours period then start all over again.  Each station will let you know when they have given you their last reading for the period (just prior to 8am when the day starts all over again).  After the last temperature of the 24 hour period is reported then they want you to produce the following information.  The highest, lowest and average temperature for each station (given in Fahrenheit for Alaska and Celsius for Greenland).  The highest, lowest and average temperatures overall (given in Fahrenheit).

Problem Statement
Assumptions:
1. Only two types of temperatures.
2. Final average of both stations must be in fahrenheit.
3.  Only one day's reading will be analyzed at a time 

Input:
1.  Location of Temperature
2.  Temperature

Calculations
Greenlandcount +1
Alaskacount + 1
Greenlandtemp = GreenlandTemp + newtemp
Alaskatemp = AlaskTemp + newtemp
GreenlandAverage = Greenlandtemp/GreenlandCount
AlaskaAverage = Alaskatemp/Alaskatemp
GreenlandAverageF = ((9/5)* GreenlandAverage)+ 32)
TempAverage = (AlaskaAverage + GreenlandAverageF)/2

Output:
The highest, lowest and average temperature for each station (given in Fahrenheit for Alaska and Celsius for Greenland).  The highest, lowest and average temperatures overall (given in Fahrenheit).
 

 

 

Now write the human Algorithm  Answer

 

 

 

 

 

 

Human Algorithm:
1.  Enter the first temperature
2.  Enter the location
3.  If Location is Alaska
     a.  Add one to Alaska count
     b.  Add temperature to Alaska Total
     c.  Compare temperature to Alaska high temperature and if great then make it new high temp
     d.  Compare temperature to Alaska low temperature and if lower then make it new low temp
4.  If Location is Greenland
     a.  Add one to Greenland count
     b.  Add temperature to Greenland Total
     c.  Compare temperature to Greenland high temperature and if great then make it new high temp
     d.  Compare temperature to Greenland low temperature and if lower then make it new low temp
5.  Ask if they have another temperature, if so return to 1.
6.   
 
 

Now Create the flowchart   Answer

Lesson7/temperatureProblem.emf

 

 

 

 

Flow Chart:

Lesson7/temperatureProblem.vls


Now Create the VB Script   Answer

 

 

 

 

 

 

 

 

<script language=vbscript>
option Explicit
Dim moretemp, temp, alaska, loopnumberak, aktempaccum, akhightemp, aklowtemp
Dim loopnumbergreen, greentempaccum, greenhightemp, greenlowtemp
Dim aktempavg, greentempavg, greenlowfah, greenhighfah, greentempavgfah, hightemp, lowtemp, tempavg

moretemp = "yes"
Do while moretemp = "yes"
    temp=cint(inputbox("What is the temperature?"))
    alaska = inputbox("Is it from alaska? yes/no")
    If alaska = "yes" then
        loopnumberak = loopnumberak + 1     '<-- Allows us to keep track of how many temperatures are reported
        aktempaccum = Cint(aktempaccum) + temp  '<-- We accumulate the temperatures to find out the average Cint is needed or the values will be joined not added
            If loopnumberak = 1 then     '<-- First time through our code the temperature reported is both our high and low temperature
                akhightemp = temp
                aklowtemp = temp
            ElseIf temp > akhightemp then  '<-- If not the first time through we see if it is higher than the last temperature we stored as the high temp
                akhightemp = temp
            elseif temp < aklowtemp then
                aklowtemp = temp
            end if
    Else
        loopnumbergreen = loopnumbergreen +1
        greentempaccum = Cint(greentempaccum) + temp
            If loopnumbergreen = 1 then
                greenhightemp = temp
                greenlowtemp = temp
            elseif temp > greenhightemp then
                greenhightemp = temp
            elseif temp < greenlowtemp then
                greenlowtemp = temp
            End if
        End if
moretemp = inputbox("More temperatures? yes/no")  '<--Let's us stop the reporting if when receive the last temperature from both stations
Loop

aktempavg = aktempaccum/loopnumberak
greentempavg=greentempaccum/loopnumbergreen
greenlowfah=(9/5)*greenlowtemp + 32     '<-- We have to convert the high/low Greenland temps to Fahrenheit to compare with Alaska
greenhighfah=(9/5)*greenhightemp + 32
greentempavgfah=(9/5)*greentempavg + 32
tempavg = (aktempavg + greentempavgfah)/2
if greenhighfah>akhightemp then      '<--We compare the converted Greenland temp and the Alaskan temp to determine which is higher
        hightemp = greenhighfah
else
        hightemp = akhightemp
end if
if greenlowfah< aklowtemp then
        lowtemp = greenlowfah
else
        lowtemp = aklowtemp
end if

Document.write("High Greenland Temperature is " & greenhightemp)
Document.write("<br>Low Greenland Temperature is " & greenlowtemp)  '<--- we use the br tag to break the line so these outputs line up under each other
Document.write("<br>Average Greenland Temperature is " & greentempavg)

Document.write("<br>High Alaska Temperature is " & akhightemp)
Document.write("<br>Low Alaska Temperature is " & aklowtemp)
Document.write("<br>Average Alaska Temperature is " & aktempavg)

Document.write("<br>High Temperature is " & hightemp)
Document.write("<br>Low Temperature is " & lowtemp)
Document.write("<br>Average Temperature is " & tempavg)


</script>