Program 8-7

posted Apr 10, 2013, 12:52 AM by Karwan Jacksi   [ updated Apr 10, 2013, 12:52 AM ]
 Program 8-71 // This program allows the user to select a month and then2 // displays how many days are in that month. It does this3 // by "looking up" information it has stored in arrays.4 #include 5 #include 6 #include 7 using namespace std;89 int main()10 {11 const int NUM_MONTHS = 12;12 int choice;13 string name[NUM_MONTHS] = {"January", "February", "March",14 "April", "May", "June",15 "July", "August", "September",16 "October", "November", "December" };1718 int days[NUM_MONTHS] = {31, 28, 31, 30,19 31, 30, 31, 31,20 30, 31, 30, 31};2122 cout << "This program will tell you how many days are "23 << "in any month.\n\n";2425 // Display the months26 for (int month = 1; month <= NUM_MONTHS; month++)27 cout << setw(2) << month << " " << name[month-1] << endl;2829 cout << "\nEnter the number of the month you want: ";30 cin >> choice;3132 // Use the choice the user entered to get the name of33 // the month and its number of days from the arrays.34 cout << "The month of " << name[choice-1] << " has "35 << days[choice-1] << " days.\n";36 return 0;37 }Program Output with Example Input Shown in BoldThis program will tell you how many days are in any month.1 January2 February3 March4 April5 May6 June7 July8 August9 September10 October11 November12 DecemberEnter the number of the month you want: 4[Enter]The month of April has 30 days.