Alright, hey everyone!
This is my first time to try this website out, so sorry if I do something incorrectly!
So, I'm attempting to create a calander using basic C++ concepts.
Honestly, I've only been doing this for about 5 weeks now, and alot of the basics of C++ are still giving me trouble.
Anyway, I'm shooting for creating a calander that takes the user input of
the year and what
day of the week that specific year starts on then outputs a single year calendar. I know it needs take into account leap years.
This is as far as I've gotten, and I'm just kind of confused as to which step I should take next.
I know I need to somehow take out the month input, because I put that in before I refined my requirements, but I'm not sure how to without losing my leap year equations!
Thank you for your help!
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
|
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int month, year;
int first_day, n_days;
cout << "Enter the year:";
cin >> year;
cout << endl;
cout << "Enter the month:";
cin >> month;
cout << endl;
cout << "Enter the first day of the year (1 for Sunday, 2 for Monday, etc.): ";
cin >> first_day;
switch (month)
{
case 2:
if((year%400==0) || (year%4==0 && year%100 !=0))
n_days = 29;
else
n_days = 28;
break;
case 4:
case 6:
case 9:
case 11:
n_days = 30;
break;
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
n_days = 31;
break;
}
cout << endl << "Sun\tMon\tTue\tWed\tThr\tFri\tSat\n";
for (int i = 1; i < first_day; i++)
{
cout << " \t";
}
for (int j = 1; j <= n_days; j++)
{
if (((j + first_day - 2) % 7 == 0) && (j != 1))
cout << endl;
cout << j << "\t";
}
cout << endl << endl;
return 0;
}
| |