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
|
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
const int ARRAY_SIZE = 13;
const int SIZE = 12;
const string months[SIZE] = {"January", "February","March","April","May",
"June","July","August","September","October","November","December"};
double localRainFall[ARRAY_SIZE];
void searchData();
void getRainFall();
void getRainFall() {
cout << "Please enter the monthly rainfall amounts\n";
for (int i = 1; i < ARRAY_SIZE; i++) {
cout << "Rainfall Amount for " << months[i - 1] << ":";
cin >> localRainFall[i + 1];
if (localRainFall[i + 1] < 0) {
cout << "Negative rainfall amounts are invalid.\n"
"Please reenter a positive rainfall amount: ";
cin >> localRainFall[i + 1];
}
} searchData();
}
void searchData() {
string monthName;
char ans;
//cout << "Search Month Name: ";
getline(cin, monthName);
do {
cout << "Search Month Name: ";
getline(cin, monthName);
for (int i = 0; i < SIZE; i++) {
if (monthName.compare(months[i]) == 0) {
cout << monthName << " Rainfall = " << localRainFall[i+2]
<< " inches" << endl;
}
}
cout << "\nEnter 'y' to search again or 'n' to exit:";
cin >> ans;
} while ((ans == 'Y') || (ans == 'y'));
}
int main() {
getRainFall();
return 0;
}
|