Viresh
12-06-2007, 10:45 AM
i am trying to make a program that shows a calendar for any given year including leap years. I am having some problems...anybody got some advice for me?
#include<iostream>
#include<string>
using namespace std;
int main( )
{
int startday, year;
bool leapyear = false;
cout << "Enter the year you want a calendar for\n";
cin >> year;
cout << "Enter the starting day in January\n";
cin >> startday;
cout << "Calendar for " << year << endl << endl;
string Months[12] = {"January", "February", "March", "April", "May", "June", "July", "August", "September",
"October", "November", "December"};
int normDays[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int leapDays[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
if ( ((year%4 ==0) && (year%100 !=0)) || ((year%4 ==0) && (year%100 ==0) && (year%400 ==0)) )
{
leapyear = true;
}
if(leapyear)
{
for (int w=0; w<12; w++)
{
cout << Months[w] << endl;
cout << "Sun\tMon\tTue\tWed\tThr\tFri\tSat\n\n";
if (w == 0)
cout << "\t";
for (int d=1; d<leapDays[w]; d++)
{
cout << d << "\t";
if (((startday + d) % 7) == 0)
{
cout << endl;
}
}// end for
cout << endl;
}//end for
}//end if
system ("pause");
return 0;
}
thanks in advance
#include<iostream>
#include<string>
using namespace std;
int main( )
{
int startday, year;
bool leapyear = false;
cout << "Enter the year you want a calendar for\n";
cin >> year;
cout << "Enter the starting day in January\n";
cin >> startday;
cout << "Calendar for " << year << endl << endl;
string Months[12] = {"January", "February", "March", "April", "May", "June", "July", "August", "September",
"October", "November", "December"};
int normDays[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int leapDays[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
if ( ((year%4 ==0) && (year%100 !=0)) || ((year%4 ==0) && (year%100 ==0) && (year%400 ==0)) )
{
leapyear = true;
}
if(leapyear)
{
for (int w=0; w<12; w++)
{
cout << Months[w] << endl;
cout << "Sun\tMon\tTue\tWed\tThr\tFri\tSat\n\n";
if (w == 0)
cout << "\t";
for (int d=1; d<leapDays[w]; d++)
{
cout << d << "\t";
if (((startday + d) % 7) == 0)
{
cout << endl;
}
}// end for
cout << endl;
}//end for
}//end if
system ("pause");
return 0;
}
thanks in advance