#include <iostream>
usingnamespace std;
int main ()
{
constint size = 50;
double temp [size] = {0}; double sum = 0;
double avg, high;
for (int i = 0; i < size ; i++)
{
cout << "Enter temperature number " << i + 1 << ":" << endl;
cin >> temp[i];
sum = sum + temp[i];
}
avg = sum / size;
high = temp[0];
for (int i = 1; i < size; i++)
{
if (temp[1] < high)
high = temp[1];
}
cout << "The average temperature is: " << avg << endl;
cout << "The highest temperature is: " << high << endl;
return 0;
}
The purpose of the program is to ask the user for a series of temperatures (no more than 50) using an array. That is what the first function should do. The second function should calculate the average of all the scores. The third function should find the highest temperature. The average and highest temperature should then be displayed to the user.
I'm not entirely sure my variables are entirely correct (meaning, I don't know that I have enough) but I know for sure that I keep trying to split this up into the functions and it isn't working for me.
#include <iostream>
usingnamespace std;
double func_sum (double temp[], int size);
double func_high (double temp[], int size);
int main ()
{
constint size = 50;
double temp [size] = {0};
double avg, high, sum = 0;
sum = func_sum (temp, size);
avg = sum / size;
high = func_high (temp, size);
cout << "The average temperature is: " << avg << endl;
cout << "The highest temperature is: " << high << endl;
return 0;
}
double func_sum (double temp[], int size)
{
double sum;
for (int i = 0; i < size ; i++)
{
cout << "Enter temperature number " << i + 1 << ":" << endl;
cin >> temp[i];
sum = sum + temp[i];
}
return sum;
}
double func_high (double temp[], int size)
{
double high = temp[0];
for (int i = 1; i < size; i++)
{
if (temp[i] > high)
high = temp[i];
}
return high;
}
For 50 number of entries use a counter and after every entry make an increment in it like counter++; then make a check that if (counter == 50) print "Memory is full."