编号及代码:
- /*
- * Copyright (c) 2014, 烟台大学计算机学院
- * All rights reserved.
- * 文件名称:test.cpp
- * 作 者:范星月
- * 完成日期:2014年 10 月 16 日
- * 版 本 号:v1.0
- *
- * 问题描述:输入年份和月份,输出本月有多少天;
- * 输入描述: 输入年份year,月份month;
- * 程序输出:输出本月?天。
- */
#include <iostream> using namespace std; int main() { int year,month; cout <<"请输入年份和月份:"; cin >>year >>month; if (month !=2) switch (month) {case 1: case 3: case 5: case 7: case 8: case 10: case 12: cout <<" 本月31天";break ; case 4: case 6: case 9: case 11: cout <<"本月30天";} else { if (year /4==0&&year/100==0||year /400!=0) cout <<"本月28天"; else cout <<"本月29天"; } return 0; }
运行结果:
学习总结:if条件句小括号后没有分号;注意你要输出cout中的内容;cout这个单词不要再写错!!!!
学习心得:不要怕出错,在错误中总结才能记得更劳。加油!!!