Develop a solution that will calculate the average temperature, given a set of temperatures. The number of temperatures may differ from time to time. (Use a trip values to stop the processing of the loop.) Test the solution with the following 10 temperatures.
78 90
85 80
87 83
75 90
86 70
#include <iostream>
using namespace std;
int main()
{
double currentTemp = 0;
double sumOfTemps = 0;
double averageTemp = 0;
int numberOfTemp = 0;
cout << "Enter number of temperatures: ";
cin >> numberOfTemp;
cout << "Enter set of temperatures using space to separate values." << endl;
for (int i = 0; i < numberOfTemp; i++)
{
cin >> currentTemp;
sumOfTemps += currentTemp;
}
averageTemp = sumOfTemps / numberOfTemp;
cout << "Average temperature for this set is: " << averageTemp << endl << endl;
return 0;
}
Comments
Leave a comment