i have been racking my brain to figure out this calendar program for days and i cant find anything close to it on any site please help!
I have to write a program that prompts the user to enter a date (month, day, and year) and the week day for this date, and displays a calendar page for any month in the same year, specified by the user after another prompt. Validate the user input and if it is invalid, ask the user to enter again. If user enters three times an invalid day or month, announce that the program will exit and exit the program. Use the following rules for determining leap years: A leap year is one whose number is exactly divisible by four. Century years, however, are only leap years if they are exactly divisible by 400. Hence 1900 was not a leap year but 2000 was. The program should not use arrays.
This is the only code i have from another problem but i cant figure out how to change it to do what this new problem asks. I appreciate any help i can get i havent been able to come up with anything so far and its driving me crazy. Thank you!
#include<iostream>
#include<cmath>
using namespace std;
int main( )
{
int n_days, start_day, year, counter=0;
cout << "What year would you like to see a calendar for? \n";
cin >> year;
cout << "Enter the first day of the month. 0 for Sunday ... 6 for Saturday\n";
cin >> start_day;
while(counter < 12)//This loop displays calender
{
switch(counter)//sets the month and total days per month
{
case 0:
cout << "January " << year << "\n";
n_days=31;
break;
case 1:
if(year%4 == 0)
{
n_days=29;
}
else
{
n_days=28;
}
cout << "February " << year << "\n";
break;
case 2:
cout << "March " << year << "\n";
n_days=31;
break;
case 3:
cout << "April " << year << "\n";
n_days=30;
break;
case 4:
cout << "May " << year << "\n";
n_days=31;
break;
case 5:
cout << "June " << year << "\n";
n_days=30;
break;
case 6:
cout << "July " << year << "\n";
n_days=31;
break;
case 7:
cout << "August " << year << "\n";
n_days=31;
break;
case 8:
cout << "September " << year << "\n";
n_days=30;
break;
case 9:
cout << "October " << year << "\n";
n_days=31;
break;
case 10:
cout << "November " << year << "\n";
n_days=30;
break;
case 11:
cout << "December " << year << "\n";
n_days=31;
break;
}
cout << "Sun\tMon\tTue\tWed\tThr\tFri\tSat\n";
//this loop sets the position for the starting day
for (int i = 0; i < start_day; i++)
{
cout << " \t";
}
//This loop displays the days
for (int j = (1+start_day); j <= (n_days+start_day); j++)
{
cout << (j-start_day) <<"\t";
if( j%7 == 0) //ends the line at the end of each week
{
cout << endl;
}
}
cout << endl;
cout << endl;
counter++;
}
cout << endl;
system("PAUSE");
return 0;
}
Aucun commentaire:
Enregistrer un commentaire