急!关于c++编日历的问题,大佬帮忙看看

#include<iostream>

#include<iomanip>

using namespace std;

class Calendar

{


public:

int weekday;

int year;

public:

//Calendar(){};

void printmonthdays();

void printtitle(int m);

int monthdays(int n);

int firstday(int year);

};

int Calendar::monthdays(int m)

{

switch(m)

{

case 1:

case 3:

case 5:

case 7:

case 8:

case 10:

case 12:

return 31;

case 4:

case 6:

case 9:

case 11:

return 30;

case 2:

if(((this->year%4==0&&this->year%100!=0)||this->year%400==0))

return 29;

else

return 28;

default:return 0;

}

}


void Calendar::printmonthdays()

{

int days;

for(int n=1;n<=12;n++)

{

printtitle(n);

days=monthdays(n);

for(int i=1;i<=days;i++)

{

cout<<setw(7)<<i;

weekday=(weekday+1)%7;//星期

if(weekday==0)

cout<<"\n";

}

cout<<"\n";

}

}


void Calendar::printtitle(int m)

{

int i; 

cout<<"\n"<<m<<"月  日     一     二     三     四     五     六 \n";

//cout<<" "; 

for(i=0;i<weekday;i++)

cout<<"       ";

}


int Calendar::firstday(int year)

{

int a,b;

a=year/100;

b=year%100-1;

return (b+(b/4)+(a/4)-2*a+(26*(13+1)/10))%7;

}

void main(int argc,char* argv[])

{

int year;

int weekday;

Calendar cal;

cout<<"请输入你要查看的年份:";

cin>>year;

weekday=cal.firstday(year);

cout<<"\n\n";

cout<<"           "<<year<<"年";

cal.printmonthdays();

cout<<"\n\n";

}

我找不到错误,麻烦帮我分析下,谢谢

逝月兮
浏览 1134回答 1
1回答

MR帽子先生

switch(m)错了,括号里面内容应该转为int类型不然是str类型的。希望对你有帮助,祝您学习愉快,有帮助的话请采纳我的答案。
打开App,查看更多内容
随时随地看视频慕课网APP