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
|
//#include "stdafx.h" // <--- Not needed outside of your VS usage.
#include <iomanip>
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
int main()
{
const int MAXSIZE = 12; // Changed name. Not necessary though. Should be the first line of main or above main.
int i = 0,
days[MAXSIZE]{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, // <--- Changed to an array.
choice = 0,
year{}, // <---Needs to be initialized.
n{}; // <---Needs to be initialized.
// Used "months" in the array. Better to show what you mean.
string month[MAXSIZE] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
// These for loops not needed if you initialize the array as I did.
//for (i = 0; i <= 6; i++)
//{
// if (i % 2 == 0)
// {
// days[i] = 31;
// }
// else
// {
// days[i] = 30;
// }
//}
//for (i = 7; i < 12; i++)
//{
// if (i % 2 == 0)
// {
// days[i] = 30;
// }
// else
// {
// days[i] = 31;
// }
//}
do
{
cout << "Enter the month number from option below: - " << endl;
for (i = 0; i < 12; i++)
{
cout << (i + 1) << " - " << month[i] << endl;
}
std::cout << "\n Enter month: ";
cin >> n;
if (n == 2)
{
cout << "Enter the year: ";
cin >> year;
bool leap = false;
if ((year % 4 == 0) && (year % 100 != 0 || year % 400 == 0))
{
cout << '\n' << year << " is a leap year." << endl;
days[1] = 29;
}
else
{
cout << '\n' << year << " is not a leap year." << endl;
days[1] = 28;
}
}
cout << '\n' << month[n - 1] << " has " << days[n - 1] << " days" << std::endl;
cout << "\n Enter 1 to continue or repeat and any other input to exit: ";
cin >> choice;
} while (choice == 1);
std::cout << "\n\n";
//system("Pause"); // <--- Not the best idea to use "system" and not really needed here with the do/while loop.
return 0;
}
|