问题及代码:
/*
*copyright (t) 2016,烟台大学计算机与控制工程学院
*All rights reserved.
*文件名称:main.cpp
*作者:郝昱猛
*完成日期:2016年3月10日
*版本号:v1.0
*问题描述:输入年份和月份,输出本月有多少天。*/
#include <iostream>
using namespace std;
int year,month;
int main()
{
cout << "请输入年份和月份:" << endl;
cin>>year>>month;
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
cout<<"本月31天"<<endl;
break;
case 4:
case 6:
case 9:
case 11:
cout<<"本月30天"<<endl;
break;
}
if(month==2)
{
if(year%4==0&&year!=0)
{
cout<<"本月29天"<<endl;
}
else
cout<<"本月28天"<<endl;
}
return 0;
}
运行结果: