Need help for leap year program using switch

So everything seems to be debugging pretty nicely. Now, I just need something that will let February show up as 29 days as opposed to 28 days if the person enters a leap year. Any help? Thanks!
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "stdafx.h"
#include <iostream>


int main()
{
	int m, y;

	std::cout << "Enter a month (1-12): \n";     // This tells the user to input a month from 1-12.
	std::cin >> m;

	std::cout << "Enter a year: \n";     // This tells the user to input a year with four-digits.
	std::cin >> y;
	

		if (y % 4 == 0)
		{
			if (y % 100 == 0)
			{
				if (y % 400 == 0)
				{
					std::cout << "This is a leap year and your chosen month has \n";     // This shows that the year is a leap year.
				}
				else
				{
					std::cout << "This is not a leap year and your chosen month has \n";     // This shows that the year is not a leap year.
				}
			}
			else
			{
				std::cout << "This is a leap year and your chosen month has \n";     // This shows that the year is a leap year.
			}
		}
		else
		{
			std::cout << "This is not a leap year and your chosen month has \n";     // This shows that the year is not a leap year.
		}


	switch (m) {
	case 1:
		std::cout << "31 days. \n";
		break;
	case 2:
		std::cout << "28 days. \n";
		break;
	case 3:
		std::cout << "31 days. \n";
		break;
	case 4:
		std::cout << "30 days. \n";
		break;
	case 5:
		std::cout << "31 days. \n";
		break;
	case 6:
		std::cout << "30 days. \n";
		break;
	case 7:
		std::cout << "31 days. \n";
		break;
	case 8:
		std::cout << "31 days. \n";
		break;
	case 9:
		std::cout << "30 days. \n";
		break;
	case 10:
		std::cout << "31 days. \n";
		break;
	case 11:
		std::cout << "30 days. \n";
		break;
	case 12:
		std::cout << "31 days. \n";
		break;
	default:
		std::cout << "Wrong input.";

	}


	// Pause Code
	int pause;
	std::cin >> pause;

    return 0;
}
Ok, so first, be clear on definition of a leap year, and what is expected to happen (for correctness of the program, not necessarily perfect history ;P).

For example, I thought you only need to check divisibility by 4 -- if divisible, it is a leap year. Correct me if I'm wrong ;P

Use a bool variable to track whether something is a leap year. If it is, as per the rules, set it to true. Later in case 2, check if it's true, outputting either 29 or 28 otherwise.
icy1 wrote:
Correct me if I'm wrong ;P

You're wrong.
ok, fine, lol, but the point is to be clear up front what a leap year is , perhaps in a Comment, so that other people don't need to read between the wiki lines for the exceptions. *Sigh* I had to scroll down so far to see that 1700, 1800, 1900 are not leap years, but 1600 and 2000 are.
Topic archived. No new replies allowed.