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
|
// Program shall prompt the user how many days it is in the month the user is stat tracking. ( has to be 28-31)
// mintemp has to be between -70 and 70, while maxtemp has to be between mintemp and 70. Downpour has to be from 0 to 200.
// Then, the program will state the average minimal temperature, average maximal temperature, and average downpour.
#include <iostream>
using namespace std;
int main() {
int nrofdays = 0;
int mintemp[] = {0};
int maxtemp[] = {0};
int totaldownpour[] = {0};
do {
cout << "How many days is there in the month you are keeping stats for? (28 - 31)" << endl;
cin >> nrofdays;
if (nrofdays > 31)
nrofdays = 0;
}
while ( nrofdays < 28);
for (int i = 0; i < nrofdays; i++) { // This is a for loop with 3 do-while loops in it to ensure error free inputs
do {
cout << "Enter minimum temperature for day " << i + 1 << ". (-70 - 70)" << endl;
cin >> mintemp[i];
if (mintemp[i] > 70)
mintemp[i] = 0;
}
while (mintemp[i] < -70);
do {
cout << "Enter max temperature for day " << i + 1 << "." << " (" << mintemp[i] << " - 70)" << endl;
cin >> maxtemp[i];
if (maxtemp[i] < mintemp[i])
maxtemp[i] = 0;
else if (maxtemp[i] > 70)
maxtemp[i] = 0;
}
while ( maxtemp[i] == 0);
do {
cout << "Enter total downpour for day " << i + 1 << ". (0 - 200)" << endl;
cin >> totaldownpour[i];
if (totaldownpour[i] > 200)
totaldownpour[i] = 0;
}
while ( totaldownpour[i] <= 0);
}
cout << "The average minimal temperature was " << ((mintemp[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]) / nrofdays) << endl;
cout << "The average maximal temperature was " << ((maxtemp[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]) / nrofdays) << endl;
cout << "The average downpour was " << ((totaldownpour[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]) / nrofdays) << endl;
system("pause");
return 0;
}
|