| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||
|
|||
|
Calendar Help...Almost finished!!!
January starts in the right location but Feb, Mar, Apr, and every other month starts in the same spot as January, I'm sooo close please help me fix this last problem......
CODE #include <iostream> #include <iomanip> #include <cmath> using namespace std; //function prototypes int First_Day_Of_Month(int y, int m); int Number_Days_Of_Month(int y, int m); bool IsLeapYear(int y); void Print_Version(); void Print_Head(int y); void Print_Month(int y, int m); void Print_Month_Head(int m); void main () { int year; Print_Version(); cin>> year; Print_Head(year); for(int i=1; i<=12; i++) { Print_Month(year, i); } cout<<"\n\n\nGoodbye!\n"; } //Some Functions void Print_Version() { cout<<"Enter any Year After 1753 to output a very pretty calendar for that year!\n"; } void Print_Head(int y) { cout<<"\n\n"<<setw(21)<<y<<endl; } void Print_Month(int year, int month) { int firstday, number_days; Print_Month_Head(month); firstday = First_Day_Of_Month(year,month); number_days = Number_Days_Of_Month(year,month); cout << " "; for(int k=0; k<firstday; k++) cout << " "; for(int i = 1; i<=number_days; i++) { cout<<setw(5)<<i; if((i + firstday)%7 == 0) { cout << endl; cout << " "; } } } bool IsLeapYear(int year) { if(year%400 == 0) { return 1; } else if (year%4 == 0 && year%100 != 0) { return 1; } else return 0; } int First_Day_Of_Month(int year, int month) { int firstday; for(month = 1; month<13; month++) { if(month<3) { month=month + 12; year=year-1; } firstday = (1 + (2 * month) + ((6 * (month + 1)) / 10) + year + (year / 4) - (year / 100) + (year / 400) + 1) % 7; } return firstday; } int Number_Days_Of_Month(int year, int month) { int Leapyear; Leapyear = IsLeapYear(year); if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) { return 31; } else if (month == 4 || month == 6 || month == 9 || month == 11) { return 30; } else if (Leapyear == 1) { return 29; } else { return 28; } } void Print_Month_Head(int month) { if(month==1) { cout<<" =================================="; cout<<"\n January\n\n Sun Mon Tue Wed Thu Fri Sat\n"; } else if(month==2) { cout<<"\n\n =================================="; cout<<"\n February\n\n Sun Mon Tue Wed Thu Fri Sat\n"; } else if(month==3) { cout<<"\n\n =================================="; cout<<"\n March\n\n Sun Mon Tue Wed Thu Fri Sat\n"; } else if(month==4) { cout<<"\n\n =================================="; cout<<"\n April\n\n Sun Mon Tue Wed Thu Fri Sat\n"; } else if(month==5) { cout<<"\n\n =================================="; cout<<"\n May\n\n Sun Mon Tue Wed Thu Fri Sat\n"; } else if(month==6) { cout<<"\n\n =================================="; cout<<"\n June\n\n Sun Mon Tue Wed Thu Fri Sat\n"; } else if(month==7) { cout<<"\n\n =================================="; cout<<"\n July\n\n Sun Mon Tue Wed Thu Fri Sat\n"; } else if(month==8) { cout<<"\n\n =================================="; cout<<"\n August\n\n Sun Mon Tue Wed Thu Fri Sat\n"; } else if(month==9) { cout<<"\n\n =================================="; cout<<"\n September\n\n Sun Mon Tue Wed Thu Fri Sat\n"; } else if(month==10) { cout<<"\n\n =================================="; cout<<"\n October\n\n Sun Mon Tue Wed Thu Fri Sat\n"; } else if(month==11) { cout<<"\n\n =================================="; cout<<"\n November\n\n Sun Mon Tue Wed Thu Fri Sat\n"; } else { cout<<"\n\n =================================="; cout<<"\n December\n\n Sun Mon Tue Wed Thu Fri Sat\n"; } } My output wont paste right here but you can see the problem, there is 5 days in the first week of every month....AAAARRRRGGGGHHHH!!!!! /*Output Enter any Year After 1753 to output a very pretty calendar for that year! 2008 2008 ================================== January Sun Mon Tue Wed Thu Fri Sat 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 ================================== February Sun Mon Tue Wed Thu Fri Sat 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 ================================== March Sun Mon Tue Wed Thu Fri Sat 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 ================================== April Sun Mon Tue Wed Thu Fri Sat 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 ================================== May Sun Mon Tue Wed Thu Fri Sat 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 ================================== June Sun Mon Tue Wed Thu Fri Sat 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 ================================== July Sun Mon Tue Wed Thu Fri Sat 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 ================================== August Sun Mon Tue Wed Thu Fri Sat 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 ================================== September Sun Mon Tue Wed Thu Fri Sat 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 ================================== October Sun Mon Tue Wed Thu Fri Sat 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 ================================== November Sun Mon Tue Wed Thu Fri Sat 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 ================================== December Sun Mon Tue Wed Thu Fri Sat 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 Goodbye! Press any key to continue */ |
|
#2
|
|||
|
|||
|
please send reply after reading this,reply is must
hi my name is lokesh I saw your program ,you lost the logic to print the date in correct place you must write a loop to avail spaces and to print the date at the right place and you must check that the dates must not be printed after saturday after that you must send a value to next month which indicates the position of the first date to be printed .that's all... can you try this short program which can print the calendar of any year right from year 1. if you had any doubt in this program you can ask me questions in this site or through Gtalk my id is lokesh755 .... Here is the program PHP Code:
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Calendar Help...Almost finished!!! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|