### Calendar Program

Hi,
So for my C++ class I am required to create a program that will "Write a program to generate a calendar for a year. The program should accept the year and the day of the week for january 1 of that year (0=Sunday, 1=Monday, etc.)" (problem statement) and I am completely stuck. Can anyone help me? I've posted what I have so far below:
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117`` ``````#include #include using namespace std; bool isLeapYear(int year); int daysInMonth(int month, bool lpYear); int printCalendar(int month); int printDay(int dow); int main () { int dow, year; cout << "What year is it?\n"; cin >> year; cout << "What day of the week does January start on? Enter 0 for Sunday, 1 for Monday, etc.\n"; cin >> dow; for(int i=1;i<13;i++) { } return 0; } bool isLeapYear(int year) { return ((year%400==0) || (year%4==0 && year%100!=0)); } int printCalendar (int month, int year) { if (month==1) cout << "January "; else if (month==2) cout << "February "; else if (month==3) cout << "March "; else if (month==4) cout << "April "; else if (month==5) cout << "May "; else if (month==6) cout << "June "; else if (month==7) cout << "July "; else if (month==8) cout << "August "; else if (month==9) cout << "September "; else if (month==10) cout << "October "; else if (month==11) cout << "November "; else if (month==12) cout << "December "; cout << setw(2) << year; cout << endl << endl; cout << "Sun " << setw(2) << "Mon " << setw(2) << "Tues " << setw(2) << "Wed " << setw(2) << "Thurs " << setw(2) << "Fri " << setw(2) << "Sat " << endl; } int daysInMonth (int month, bool lpYear) { int daysinmonth; switch(month) { case 1://jan daysinmonth=31; break; case 2://feb if(lpYear = true) daysinmonth = 29; else daysinmonth = 28; break; case 3://march daysinmonth = 31; break; case 4://april daysinmonth = 30; break; case 5://may daysinmonth = 31; break; case 6://june daysinmonth = 30; break; case 7://july daysinmonth = 31; break; case 8://august daysinmonth = 31; break; case 9://sept daysinmonth = 30; break; case 10://oct daysinmonth = 31; break; case 11://nov daysinmonth = 30; break; case 12://dec daysinmonth = 31; break; } return daysinmonth; } int printDay(int dow) { for (days[i]) { int day = StartDay; cout << num; day++; if (day > 7) { cout << endl; day = 1; } } }``````
This doesn't use all the nice code you have written but maybe you will get some ideas from it.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100`` ``````#include #include using namespace std; bool isLeapYear(int year); int daysInMonth(int month, bool lpYear); int printCalendar(int month); int printDay(int dow); string daysofweek="Su Mo Tu We Th Fr Sa"; int month=1; // What month is it int maxdaysinmonth=0; // Max days to print for month int endofweek=6; // end of week is Sa int startingspaces=0; // leading spaces int daycount=1; // Current day to print int main () { int dow, year; cout << "What year is it?\n"; cin >> year; cout << "What day of the week does January start on? Enter 0 for Sunday, 1 for Monday, etc.\n"; cin >> dow; // Print Year cout << "\t" << year << endl<< endl; // Print Month if (month==1) { cout << " January" << endl; maxdaysinmonth = 31; } cout << daysofweek << endl; // Determine leading spaces if (dow==0) {startingspaces=1;} else if (dow==1) {startingspaces=4;} else if (dow==2) {startingspaces=7;} else if (dow==3) {startingspaces=10;} else if (dow==4) {startingspaces=13;} else if (dow==5) {startingspaces=16;} else if (dow==6) {startingspaces=19;} for (int i=1; i <=startingspaces;i++) {cout << " ";} while (daycount < 10) { if (daycount < 9) { cout << daycount << " "; } else { cout << daycount<< " "; } daycount++; if (dow==6) { cout << endl << " "; dow=0; } else {dow++;} } while (daycount <=maxdaysinmonth) { cout << daycount << " "; daycount++; if (dow==6) { cout << endl; dow=0; } else {dow++;} } month++; cout << endl; cout << "Next Month = " << month << endl; cout << "Starting day of week for next month: " << dow << endl; return 0; } bool isLeapYear(int year) { return ((year%400==0) || (year%4==0 && year%100!=0)); } ``````

Output:
 ``123456789101112131415`` ``````What year is it? 2013 What day of the week does January start on? Enter 0 for Sunday, 1 for Monday, etc. 2 2013 January Su Mo Tu We Th Fr Sa 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 Next Month = 2 Starting day of week for next month: 5``````
Last edited on
 I am required to create a program that will "Write a program to generate a calendar for a year.

Are you required to(?):

-Write a program which generates a calendar.
-Write a program which writes a program which generates a calendar.
Topic archived. No new replies allowed.