|
I use the same SWITCH to do it, but it shows an error: help solve it ::
#include <iostream.h>
#include <conio.h>
#include <iomanip.h>
void days31 ();
void days ();
int main () {
// declare and initialise variables
int month = 1;
// obtian the month in list
cout << "\n\n January (1)";
cout << "\n\n February (2)";
cout << "\n\n March (3)";
cout << "\n\n April (4)";
cout << "\n\n May (5)";
cout << "\n\n June (6)";
cout << "\n\n July (7)";
cout << "\n\n August (8)";
cout << "\n\n September (9)";
cout << "\n\n October (10)";
cout << "\n\n November (11)";
cout << "\n\n December (12)";
cout << "\n Please select the month:";
// user input a month
cin >> month;
switch (month) {
// in those cases the days will be display 31 days
case 1: case 3: case 5:
case 7: case 8: case 10:
case 12:
days31 ();
break;
// in this case the days will be display 28 days
case 2:
cout << "\n 28"; // days28 ();
break;
// in those cases the days will be display 30 days
case 4: case 6: case 9: case 11:
cout << "\n 30"; // days30 ();
break;
// other input will be show a error message
default:
cout << "\n error messages !!! it is not correct input, please try again";
}
The
getch ();
return 0;
}
// this function will display 31 days in "days31" function
void days31 () {
The
// obtian and initialise variables
int day = 1;
int maxrow = 6;
int maxcol = 6;
int date = 0;
The
The
// obtain the sharp of calendar from Sun to Sat
cout << "\n 1. Sunday";
cout << "\n 2. Monday";
cout << "\n 3. Tuesday";
cout << "\n 4. Wednsday";
cout << "\n 5. Thusday";
cout << "\n 6. Friday";
cout << "\n 7. Saturday";
// user input the day
The
cout << "\n\n Please Insert the day you wanted:";
cin >> date;
The
days (); // display the dates from Sun to Sat
The
if (date> 0&&date <= 7) {
for (int row = 1; row <= maxrow&&day <= 31; row ++)
for (int col = 0; col <= maxcol&&day <= 31; col ++)
The
if (day <= 31) {// month have 31 day
cout << setw (6) << day ++; // print out the number from 1-31 by 6 spaces
The
}
else {
cout << "\n\nError !!!! Please try again";
}
The
The
The
The
The
void days () {
The
The
cout << setw (6) << "Sun";
cout << setw (6) << "Mon";
cout << setw (6) << "Tue";
cout << setw (6) << "Wed";
cout << setw (6) << "Thu";
cout << setw (6) << "Fri";
cout << setw (6) << "Sat";
The
} |
|