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
|
#include <iostream>
#include <string>
using std::cout;
using std::cin;
using std::endl;
using std::string;
// Example program
int main()
{
int day, month;
string Rain[4][5] = {
{ "January", "24.5", "28.4", "23.5", "21.8" },
{ "February", "20.2", "13.8", "2.9", "-.1" },// "-.1" would be on 29th, 30th and 31st
{ "March", "14.5", "24.7", "19.5", "28.1" },
{ "April", "19.6", "14.9", "9.3", "22.2" }
// Have each month have 31 days data, with a -.1 in calendar day past actual days in the given month
};
do
{
printf("Enter the selected month (1 to 4 only ): ");
cin >> month;
if (month < 1 || month >4)
printf("Sorry, that was an invalid month. Please try again.\n");
} while (month < 1 || month >4);
month--;// Subtract 1, to have 0 to 11 for month
do
{
printf("Enter the selected day (1 to 4 only ): ");
cin >> day;
if (Rain[month][day] == "-.1")
printf("Sorry, the month selected, does not have %d days. Try again.\n", day);
if (day > 4)
printf("Sorry, that was an invalid day for the month of %s\n", Rain[month][0].c_str());
} while ((day < 1 || day > 4) || Rain[month][day] == "-.1");
printf("The average rainfall for %s %d, was %s inches.\n", Rain[month][0].c_str(), day, Rain[month][day].c_str());
cin >> day;
return 0;
}
|