//case后面改成数值,不是字符;
#include
using namespace std;
void main()
{int month;
cout<<"input a month between 1--12:";
cin>>month;
switch(month)
{
case 1:cout<<"January 31days\n";
break;
case 2:cout<<"February 28or29days\n";
break;
case 3:cout<<"March 31days\n";
break;
case 4:cout<<"April 30days\n";
break;
case 5:cout<<"May 31days\n";
break;
case 6:cout<<"June 30days\n";
break;
case 7:cout<<"July 31days\n";
break;
case 8:cout<<"August 31days\n";
break;
case 9:cout<<"September 30days\n";
break;
case 10:cout<<"October 31days\n";
break;
case 11:cout<<"November 30days\n";
break;
case 12:cout<<"December 31days\n";
break;
default:cout<<"the number is wrong.\n";
break;
}
}
改成 case 1 这样子,不要引号
#include
using namespace std;
void main()
{int month;
cout<<"input a month between 1--12:";
cin>>month;
switch(month)
{
case 1:cout<<"January 31days\n";
break;
case 2:cout<<"February 28or29days\n";
break;
case 3:cout<<"March 31days\n";
break;
case 4:cout<<"April 30days\n";
break;
case 5:cout<<"May 31days\n";
break;
case 6:cout<<"June 30days\n";
break;
case 7 :cout<<"July 31days\n";
break;
case 8 :cout<<"August 31days\n";
break;
case 9 :cout<<"September 30days\n";
break;
case 10 :cout<<"October 31days\n";
break;
case 11 :cout<<"November 30days\n";
break;
case 12 :cout<<"December 31days\n";
break;
default:cout<<"the number is wrong.\n";
break;
}
}
一楼正解