打印某个月的月历

2016-07-11  本文已影响0人  Roc_J
#include <iostream>
#include <iomanip>
using namespace std;
int main(void)
{
    int days,week;
    cout << "Please input the days and week:" << endl;
    cin >> days >> week;
    if(days<28 || days>31) cout << "Error days!" << endl;
    if(week<1 || week>7) cout << "Error week!" << endl;
    cout << " MON TUE WED THU FRI SAT SUN" << endl;
    cout << " ===========================" << endl;
    for(int i=1; i<week; i++) cout << setw(4) << " ";
    for(i=1; i<=days; i++)
    {
        cout << setw(4) << i;
        if((i+week-1)%7==0) cout << endl;
    }
    cout << endl << " ===========================" << endl;
    return 0;
}
上一篇 下一篇

猜你喜欢

热点阅读