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!
#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.
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.