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
|
#include <iostream>
#include <string>
using std::cin;
using std::cout;
using std::string;
using std::endl;
int
main()
{
// declare variables
int mynum = 0;
char ans = ' ';
string allMonths[12] =
{ "January", "Feburary", "March", "April", "May", "June",
"July", "August","September", "October", "November", "December" };
string allFlowers[12] =
{ "Carnation", "Iris", "Daffodil", "Daisy", "Lily of the Valley",
"Rose","Sunflower", "Gladiolus", "Aster", "Snapdragon",
"Chrysanthemum", "Orchid" };
// Print the header only once
system("cls");
system("color f0");
cout << "\t\t******************************" << endl;
cout << "\t\t* Anonymous *" << endl;
cout << "\t\t* CPT-168-A01 *" << endl;
cout << "\t\t* Month Array *" << endl;
cout << "\t\t******************************" << endl << endl;
// When validating input, the test to break out of the loop
// is in the middle of the logic. Rather than fighting it, I
// just code it that way.
while (true) {
cout << "Please enter the month you were born (1-12) : " << endl;
cin >> mynum;
if (mynum > 0 && mynum <= 12) {
break;
}
cout << "Month must be between 1 and 12\n";
}
cout << "You entered month " << mynum << '\n';
// TO DO: Print the month and flower. Remember that the user
// entered a number from 1 to 12, but the array indexes go from 0
// to 11.
// TO DO: put everything above in a loop. Add code to prompt user
// to continue
cout << " T H A N K Y O U " << endl << endl;
system("pause");
return 0;
}
|