Hello guys I an having some issues with this program. It will compile but will but keeps giving me errors. (invalid temparture value) I will appreciate if somebody can give it a look over. I put the lab instructions to give you an idea of what the objective is.
**************************************************************************
Structured Data and Abstract Data Types Lab
Your Mission: Write a program that uses a structure to store the following data for each month:
Member Name: Description:
* * * * * * * * * * * * * * *
rain total rainfall
high high temperature
low low temperature
averageTem average temperature
The program should have an array of 12 structures to hold weather data for an entire year. When the program runs, it should ask the user to enter data for each month. Once the data are entered for all the months, the program should calculate and display the average monthly rainfall, the total rainfall for the year, the highest and lowest temperatures for the year (and the months they occurred in), and the average of all the monthly average temperatures.
Input validation should include checking for temperatures within the range between -100 and +140 degrees fahrenheit.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
// Constant for the number of months
const int num_months = 12;
// Declaration of the WeatherInfo structure
struct weatherInfo
{
double rain[num_months];
double high[num_months];
double low[num_months];
double averageTemp[num_months];
double yearlyMonthlyRainfall(double weather[])
{
int count{0};
double sum{0};
while(count < 12)
{
sum += weather[count];
count++;
}
double average = sum / 12;
return average;
}
};
int main(){
double temp;
double low1;
double average2;
weatherInfo Info;
// Create an array of WeatherInfo structures
// Get the weather data for each month.
cout << "Enter the following information:\n";
for (size_t count = 0; count <= 11; count++)
{
cout << " Enter total rainfall for month " << count + 1 << ":" << endl;
cin >> Info.rain[count];
cout << " enter the highest temperature reading for month " << count + 1 << ":" << endl;
cin >> temp;
if (temp >= -100 && temp <= 140)
{
Info.high[count] = temp;
}
else
{
Info.low[count] = temp;
}
cout << "Invalid temperature value" << endl;
exit (0);
{
cout << "enter the lowest temperature reading for month " << count + 1 << ":" << endl;
cin >> low1;
}
if (low1 >= -100 && low1<= 140)
{
Info.low[count] = low1;
}
else
{
cout << "Invalid temperature value" << endl;
exit(0);
}
cout << "enter the average temperature for month " << count + 1 << ":" << endl;
cin >> average2;
if (average2 >= -100 && average2<= 140)
{
Info.averageTemp[count] = average2;
}
else
{
cout << "Invalid temperature value" << endl;
exit(0);
}
return 0;
}
}
|