#include <iostream> using namespace std; int main() { // 控制结构:顺序结构、选择结构和循环结构 // 选择结构:if单选、if...else双选和switch多选结构 // 循环结构:while、for、do...while // 三个语句:break、continue和goto // 两种连接控制结构的方式:嵌套和堆叠 cout << "********************************************************" << endl; cout << "* Welcome *" << endl; cout << "* 1 to Leap Year Judging *" << endl; cout << "* 2 to Palindromic Judging *" << endl; cout << "* 3 to Date Judging *" << endl; cout << "* 0 to Exit the app *" << endl; cout << "********************************************************" << endl; int choice; cout << "Welcome to the Games, 0 to exit,(1-3) to the Game!\n"; cin >> choice; while(choice) { if(0==choice) { return 0; } if(1==choice) { // Leap year int year; int selection; cout << "Welcome to Leap Year Judging App!" << endl; cout << " 1 to continue, 0 to exit: "; cin >> selection; while(selection) { cout << "Input a year: "; cin >> year; if( ( 0==year%400 )||( 0!=year%100 && 0==year%4) ) { cout << "Year:" << year << " is a leap year " << endl; } else { cout << "Year:" << year << " is not a leap year " << endl; } cout << "Welcome to Leap Year Judging App again!" << endl; cout << " 1 to continue, 0 to exit: "; cin >> selection; } } if(2==choice) { // Palindromic, 5digits int num; int selection; cout << "Welcome to Palindromic Judging App!" << endl; cout << " 1 to continue, 0 to exit: "; cin >> selection; while(selection) { cout << "Input a num: "; cin >> num; // 12321 12345 if( ( num/10000==num%10 )||( num%10000/1000==num%100/10) ) { cout << "Number:" << num << " is a Palindromic number " << endl; } else { cout << "Number:" << num << " is not a Palindromic number " << endl; } cout << "Welcome to Palindromic Judging App again!" << endl; cout << " 1 to continue, 0 to exit: "; cin >> selection; } } if(3==choice) { // Date int month, day, year; int dayth=0; int selection; cout << "Welcome to Date Judging App!" << endl; cout << " 1 to continue, 0 to exit: "; cin >> selection; while(selection) { cout << "Input a Date: "; cin >> month >> day >> year; int Days[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; if( ( 0==year%400 )||( 0!=year%100 && 0==year%4) ) { Days[2]++; } for(int i=1; i<month; i++) { dayth += Days[i]; } dayth += day; cout << "Date: " << month << ", " << day << " " << year << " is the " << dayth << "th day in the year: " << year << endl; cout << "Welcome to Leap Year Judging App again!" << endl; cout << " 1 to continue, 0 to exit: "; cin >> selection; } } if(4==choice) { // new function } cout << "********************************************************" << endl; cout << "* Welcome *" << endl; cout << "* 1 to Leap Year Judging *" << endl; cout << "* 2 to Palindromic Judging *" << endl; cout << "* 3 to Date Judging *" << endl; cout << "* 0 to Exit the app *" << endl; cout << "********************************************************" << endl; //int choice;// the inner choice hided the outer choice cout << "Welcome to the Games, 0 to exit,(1-3) to the Game!\n"; cin >> choice; } return 0; }
0.0分
0 人评分
C语言网提供由在职研发工程师或ACM蓝桥杯竞赛优秀选手录制的视频教程,并配有习题和答疑,点击了解:
一点编程也不会写的:零基础C语言学练课程
解决困扰你多年的C语言疑难杂症特性的C语言进阶课程
从零到写出一个爬虫的Python编程课程
只会语法写不出代码?手把手带你写100个编程真题的编程百练课程
信息学奥赛或C++选手的 必学C++课程
蓝桥杯ACM、信息学奥赛的必学课程:算法竞赛课入门课程
手把手讲解近五年真题的蓝桥杯辅导课程
发表评论 取消回复