int month;
int days;
int numdays;
int monthstarter=1;
cout%26lt;%26lt;"Enter a month (1 - 12): ";
cin%26gt;%26gt;month;
cout%26lt;%26lt;"Enter a starting day (0 for Sunday, 1 for Monday...): ";
cin%26gt;%26gt;days;
if (month==1){
cout%26lt;%26lt;"\t\tJanuary"%26lt;%26lt;endl;
numdays=31;
}
else if (month==2){
cout%26lt;%26lt;"\t\tFebuary"%26lt;%26lt;endl;
numdays=28;
}
else if (month==3){
cout%26lt;%26lt;"\t\tMarch"%26lt;%26lt;endl;
numdays=31;
}
else if (month==4){
cout%26lt;%26lt;"\t\tApril"%26lt;%26lt;endl;
numdays=30;
}
else if (month==5){
cout%26lt;%26lt;"\t\tMay"%26lt;%26lt;endl;
numdays=31;
}
else if (month==6){
cout%26lt;%26lt;"\t\tJune"%26lt;%26lt;endl;
numdays=30;
}
else if (month==7){
cout%26lt;%26lt;"\t\tJuly"%26lt;%26lt;endl;
numdays=31;
}
else if (month==8){
cout%26lt;%26lt;"\t\tAugust"%26lt;%26lt;endl;
numdays=31;
}
else if (month==9){
cout%26lt;%26lt;"\t\tSeptember"%26lt;%26lt;endl;
numdays=30;
}
else if (month==10){
cout%26lt;%26lt;"\t\tOctober"%26lt;%26lt;endl;
numdays=31;
}
else if (month==11){
cout%26lt;%26lt;"\t\tNovember"%26lt;%26lt;endl;
numdays=30;
}
else if (month==12){
cout%26lt;%26lt;"\t\tDecember"%26lt;%26lt;endl;
numdays=31;
}
cout%26lt;%26lt;"\tS M T W T F S"%26lt;%26lt;endl;
cout%26lt;%26lt;"-------------------------------...
Someone please finish this program- need to make a calendar program in c++?
Use a table instead of a switch or if statement.
struct sMonth
{
char Label[32];
int Days;
};
sMonth gMonth[12] =
{
{"Jan", 30},
{"Feb", 28},
};
You should be able to figure the rest out.
Reply:alright, you might wanna consider using a switch statement, and also using the iomanip lable you can use set w, which'll make it easier on yourself on lining up:
switch (month)
(
case 1: //for january
cout %26lt;%26lt; setw(9) %26lt;%26lt; cout %26lt;%26lt; "January\n"; // setw basically just makes the following cout statement take that many places, even if it means adding spaces to the left
numdays = 30;
break;
//continue using switch statements, it makes it easier on yourself
// then with the actual outputting u should use a loop, i would suggest a 'for' loop... probably nested
// as another suggestion, you don't want to use the tab character, because that limits your control on how you'll output things... I'll assume you know the 'for' loop, and let you run on your own, make sure u practice with setw, its very handy
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment