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 %26lt;iostream%26gt;
#include %26lt;iomanip%26gt;
#include %26lt;cmath%26gt;
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%26gt;%26gt; year;
Print_Head(year);
for(int i=1; i%26lt;=12; i++)
{
Print_Month(year, i);
}
cout%26lt;%26lt;"\n\n\nGoodbye!\n";
}
//Some Functions
void Print_Version()
{
cout%26lt;%26lt;"Enter any Year After 1753 to output a very pretty calendar for that year!\n";
}
void Print_Head(int y)
{
cout%26lt;%26lt;"\n\n"%26lt;%26lt;setw(21)%26lt;%26lt;y%26lt;%26lt;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 %26lt;%26lt; " ";
for(int k=0; k%26lt;firstday; k++)
cout %26lt;%26lt; " ";
for(int i = 1; i%26lt;=number_days; i++)
{
cout%26lt;%26lt;setw(5)%26lt;%26lt;i;
if((i + firstday)%7 == 0)
{
cout %26lt;%26lt; endl;
cout %26lt;%26lt; " ";
}
}
}
bool IsLeapYear(int year)
{
if(year%400 == 0)
{
return 1;
}
else if (year%4 == 0 %26amp;%26amp; year%100 != 0)
{
return 1;
}
else
return 0;
}
int First_Day_Of_Month(int year, int month)
{
int firstday;
for(month = 1; month%26lt;13; month++)
{
if(month%26lt;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%26lt;%26lt;" ==================================";
cout%26lt;%26lt;"\n January\n\n Sun Mon Tue Wed Thu Fri Sat\n";
}
else if(month==2)
{
cout%26lt;%26lt;"\n\n ==================================";
cout%26lt;%26lt;"\n February\n\n Sun Mon Tue Wed Thu Fri Sat\n";
}
else if(month==3)
{
cout%26lt;%26lt;"\n\n ==================================";
cout%26lt;%26lt;"\n March\n\n Sun Mon Tue Wed Thu Fri Sat\n";
}
else if(month==4)
{
cout%26lt;%26lt;"\n\n ==================================";
cout%26lt;%26lt;"\n April\n\n Sun Mon Tue Wed Thu Fri Sat\n";
}
else if(month==5)
{
cout%26lt;%26lt;"\n\n ==================================";
cout%26lt;%26lt;"\n May\n\n Sun Mon Tue Wed Thu Fri Sat\n";
}
else if(month==6)
{
cout%26lt;%26lt;"\n\n ==================================";
cout%26lt;%26lt;"\n June\n\n Sun Mon Tue Wed Thu Fri Sat\n";
}
else if(month==7)
{
cout%26lt;%26lt;"\n\n ==================================";
cout%26lt;%26lt;"\n July\n\n Sun Mon Tue Wed Thu Fri Sat\n";
}
else if(month==8)
{
cout%26lt;%26lt;"\n\n ==================================";
cout%26lt;%26lt;"\n August\n\n Sun Mon Tue Wed Thu Fri Sat\n";
}
else if(month==9)
{
cout%26lt;%26lt;"\n\n ==================================";
cout%26lt;%26lt;"\n September\n\n Sun Mon Tue Wed Thu Fri Sat\n";
}
else if(month==10)
{
cout%26lt;%26lt;"\n\n ==================================";
cout%26lt;%26lt;"\n October\n\n Sun Mon Tue Wed Thu Fri Sat\n";
}
else if(month==11)
{
cout%26lt;%26lt;"\n\n ==================================";
cout%26lt;%26lt;"\n November\n\n Sun Mon Tue Wed Thu Fri Sat\n";
}
else
{
cout%26lt;%26lt;"\n\n ==================================";
cout%26lt;%26lt;"\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
*/
C++ Calander Program .......I'm sooooo close, I need your help.?
i suspect the firstdayofmonth() function. it is not clear what it does and it seems to return the same value for each month.
here's the way i would approach it.
int firstdayofyear(int year)
{ do whatever to figure out the first weekday of the year}
int firstdayofmonth(int month, year)
{int prevmonth = 1, firstday = firstdayofyear(year);
while (prevmonth %26lt; month)
do
{
firstday += numberofdaysofmonth(month, year);
prevmonth++
}
firstday = firstday mod 7;
return firstday}
this separates the year calculations from the month calculations.
elephant ear
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment