This is what I have so far. Can someone help me with my if statements, to get February to print with 29 days during a leap year? And also to get the first week of each month aligned correctly?
You shouldn't need to enter the weekday of January 1.
You can find it out pretty easily like this.
(Maybe someone will also post a more modern way of doing this.)
// find day of week that year y starts on
#include <iostream>
#include <ctime>
int start_weekday_of_year(int y) {
// set up the tm structure (https://en.cppreference.com/w/c/chrono/tm)
std::tm t {}; // zero all fields; note that a tm_mon of 0 means January
t.tm_mday = 1;
t.tm_year = y - 1900;
// call mktime on it to normalize the fields,
// which includes filling in the weekday value.
std::mktime(&t);
return t.tm_wday; // 0 (Sun) to 6 (Sat)
}
int main() {
constchar* const day_names[] {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
for (;;) {
int y;
std::cin >> y;
int d = start_weekday_of_year(y);
std::cout << "Year " << y << " starts on " << day_names[d] << '\n';
}
}