PDA

View Full Version : c++


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

Inigoesdr
12-06-2007, 11:32 AM
What kind of problems are you having? And did you try to solve them yourself by searching?

Viresh
12-06-2007, 11:35 AM
Yea i tried, but the problem is the days aren't coming out right, and its supposed to be in tabular format, but the tabs are aligning wrong, and i can't figure out wtf is happening.... thanks for the help... can you run the code yourself?