Program 8-5

posted Apr 10, 2013, 12:51 AM by Karwan Jacksi   [ updated Apr 10, 2013, 12:51 AM ]
Program 8-5
1 // This program displays the number of days in each month.
2 #include <iostream>
3 #include <iomanip>
4 using namespace std;
5
6 int main()
7 {
8 const int NUM_MONTHS = 12;
9 int days[NUM_MONTHS];
10
11 days[0] = 31; // January
12 days[1] = 28; // February
13 days[2] = 31; // March
14 days[3] = 30; // April
15 days[4] = 31; // May
16 days[5] = 30; // June
17 days[6] = 31; // July
18 days[7] = 31; // August
19 days[8] = 30; // September
20 days[9] = 31; // October
21 days[10] = 30; // November
22 days[11] = 31; // December
23
24 for (int month = 0; month < NUM_MONTHS; month++)
25 {
26 cout << "Month " << setw(2) << (month + 1) << " has ";
27 cout << days[month] << " days.\n";
28 }
29 return 0;
30 }
Program Output
Month 1 has 31 days.
Month 2 has 28 days.
Month 3 has 31 days.
Month 4 has 30 days.
Month 5 has 31 days.
Month 6 has 30 days.
Month 7 has 31 days.
Month 8 has 31 days.
Month 9 has 30 days.
Month 10 has 31 days.
Month 11 has 30 days.
Month 12 has 31 days.
Comments