12-element int array named days

Declare a 12-element int array named days. Assign the number of days in each month to the array, using 28 for February. Code the program so that it displays the number of days corresponding to the month number entered by the user. For example, when the user enters the number 7, the program should display the number 31. The program also should display an appropriate message when the user enters an invalid month number. Use a sentinel value to end the program.

please help :(
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include<iostream>
using namespace std;
int main()
{

	int num; // Stores the month the user wants to see how many days are in.
	int days[12] = {31,28,31,30,31,30,31,31,30,31,30,31}; 


	cout << "Enter a number of the month to see the number of days in that month: ";
         // getting the month the user wants to see the number of days in that month
	cin >> num;
          // decrementing num because arrays begin at 0.
	num--;

	// display days per month


	cout << "Days of this month equal: " << days[num] << endl; 

	return 0;
}
Last edited on

You need to be looking at using flow control, i.e. IF statement.

http://www.cplusplus.com/doc/tutorial/control/

Topic archived. No new replies allowed.