Global warming. As part of a global warming analysis, a research facility tracks
ID: 3761448 • Letter: G
Question
Global warming.
As part of a global warming analysis, a research facility tracks outdoor temperatures at the North Pole
once a day, at noon, for a year. At the end of each month, these temperatures are entered into the
computer and processed. The operator will enter 28, 29, 30, or 31 data items, depending on the month.
You may use 500 as a sentinel value after the last temperature, since that is lower than absolute 0.
Your main program should call the read_temps(), hot_days(), and print_temps() functions described:
(b) Write a function, read_temps(), that has one parameter, an array called temps, in which to store
the temperatures. Read the real data values for one month and store them into the slots of an array.
Return the actual number of temperatures read as the result of the function.
(c) Write a function, hot_days(), that has two parameters: the number of temperatures for the current
month and an array in which the temperatures are stored. Search through the temperature array
and count all the days on which the noon temperature exceeds 32F. Return this count.
(d) Write a function, print_temps(), with the same two parameters plus the count of hot days. Print
a neat table of temperatures. At the same time, calculate the average temperature for the month
and print it at the end of the table, followed by the number of hot days.
Heres my program but it doesnt work properly :(
//Ryan J. Fleming - CSCI1110 Section 01
//Program 7 - Global Warming
#include <stdio.h>
int read_temps (float temps[]);
int hot_days (int numOfTemp, float temps[]);
int printf_temps (int numOfTemp, float temps[], int numOfHotDays);
int main (void)
{
int index = 0;
float temps[31];
int numOfTemp, numOfHotDays;
numOfTemp = read_temps (temps);
numOfHotDays = hot_days (numOfTemp, temps);
printf_temps (numOfTemp, temps, numOfHotDays);
return 0;
}
int hot_days (int numOfTemp, float temps[])
{
int i;
int count = 0;
for (i = 0; i < numOfTemp; i++)
{
if (temps[i] > 32.0)
count++;
}
return count;
}
int printf_temps (int numOfTemp, float temps[], int numOfHotDays)
{
float sum = 0.0;
int i;
printf (" Input Temperatures:");
printf (" -------------------------");
for (i = 0;i < numOfTemp; i++)
{
printf (" Day %d : %.2fF", i+1, temps[i]);
sum = sum + temps[i];
}
printf (" Number of Hot Days : %d", numOfHotDays);
printf (" Average Temperature: %.2f ", sum/numOfTemp);
}
Explanation / Answer
You are having the sub-functions that you want to call from main embedded within the own scope within main itself that wil not works good
first you need to do is to first move them outside of main and add the declaration lines. Then you need to call them from main.
code for reading temp if u need addd at ur last of code
int read_temps (float temps[])
{
int index = 0;
float tempVal;
do
{
printf ("Enter the temperature:");
scanf ("%f", &tempVal);
if (tempVal!=-500.0)
{
temps[index] = tempVal;
index++;
}
}
while (tempVal != -500.0);
return index;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.