Please note that this is not a homework site. We won't do your homework for you. The purpose of homework is that you learn by doing. However we are always willing to help solve problems you encountered, correct mistakes you made in your code and answer your questions.
We didn't see your attempts to solve this problem yourself and so we cannot correct mistakes you didn't made and answer questions you didn't ask. To get help you should do something yourself and get real problems with something. If your problem is "I don't understand a thing", then you should go back to basics and study again.
You promised:
Challenging code
but there is no code, not even simple code, within your post. False advertising.
cout<<"Please enter a year (example: 1999) : ";
cin>>year;
if ((year % 400 == 0) || ((year % 100 == 0) ^ (year % 4 == 0)))
{
cout << "\nThe year is leap year.";
}
else
{
cout << "\nThe year is odd year.";
}
return year;
}
int determinedaycode(int year)
{
int daycode;
cout << "\nEnter the first day of January: 1 for Monday, 2 for Tuesday etc. ";
cin >> daycode;
while (daycode < 0 || daycode > 7)
{
cout << "\nThe number entered is invalid.\nPlease enter a number between 1 and 7. ";
cin >> daycode;
}
return daycode;
}
int determineleapyear(int year)
{
if (year % 4 == FALSE && year % 100 != FALSE || year % 400 == FALSE)
{
days_in_month[2] = 29;
return TRUE;
}
else
{
days_in_month[2] = 28;
return FALSE;
}
}
void calendar(int year, int daycode)
{
int month, day;
for (month = 1; month <= 12; month++)
{
cout<<months[month];
cout<<"\n\nSun Mon Tue Wed Thu Fri Sat\n";
// Correct the position for the first date
for (day = 1; day <= 1 + daycode * 5; day++)
{
cout<<" ";
}
// Print all the dates for one month
for (day = 1; day <= days_in_month[month]; day++)
{
cout<< setw(2)<<day;
// Is day before Sat? Else start next line Sun.
if ((day + daycode) % 7 > 0)
cout<<" ";
else
cout<<"\n ";
}
// Set position for next month
daycode = (daycode + days_in_month[month]) % 7;
}
}
int main(void)
{
int year, daycode, leapyear;
year = inputyear();
daycode = determinedaycode(year);
determineleapyear(year);
calendar(year, daycode);
cout<<"\n";
}
Sorry I should have posted it before.
So i am having trouble with this part.
int determinedaycode(int year)
{
int daycode;
cout << "\nEnter the first day of January: 1 for Monday, 2 for Tuesday etc. ";
cin >> daycode;
while (daycode < 0 || daycode > 7)
{
cout << "\nThe number entered is invalid.\nPlease enter a number between 1 and 7. ";
cin >> daycode;
}
return daycode;
}
In the while loop i dont know how to catch the wrong inputs if the user entered a char just say somebodys name
Thanx that cleared a lot of things.
I have one more question..
My program prints the months beneath each other but I want to print to print them beside each other....
I know i should be figuring it out by myself but if somebody can guide a little bit it will be a great help
Plz and thnx