本文主要是介绍干支、生肖查询器 v2.0,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
//***********************************
//*程序名:判断干支与生肖
//*功 能:输入公元纪年,判断干支与生肖
//*编制人:刘聪
//*创建时间:2017年1月24日
//*修改时间:2017年9月22日(v2.0)
//***********************************
#include <iostream>
#include <cstring>
#include <cstdlib>
using namespace std; int main()
{ int GetInteger();void JudgeYear(int year);while(1){cout << "请输入需要判断的年号:"; int year = GetInteger();cout << endl;if(year == 0){system("pause"); return 0; }else{JudgeYear(year);cout << endl;cout << "*******************************************" << endl; cout << endl << "若要退出程序,请直接按数字0;否则请继续输入。" << endl << endl; }}return 0;
} int GetInteger(){ char buf[100] = {0}; while(strlen(buf) == 0) //用户直接输入回车 cin.getline(buf, 100); return atoi(buf); //atoi函数是cstring头文件自带的
} void JudgeYear(int year){int a, b, c;a = (year % 10 + 7);if(a > 10) a = (a - 10); c = b = (year % 12 + 9);if(b > 12) c = b = (b - 12); cout<<year<<"年是‘"; switch( a ) { case 1:cout<<"甲";break; case 2:cout<<"乙";break; case 3:cout<<"丙";break; case 4:cout<<"丁";break; case 5:cout<<"戊";break; case 6:cout<<"己";break; case 7:cout<<"庚";break; case 8:cout<<"辛";break; case 9:cout<<"壬";break; case 10:cout<<"癸";break; default:;break; } switch( b ) { case 1:cout<<"子";break; case 2:cout<<"丑";break; case 3:cout<<"寅";break; case 4:cout<<"卯";break; case 5:cout<<"辰";break; case 6:cout<<"巳";break; case 7:cout<<"午";break; case 8:cout<<"未";break; case 9:cout<<"申";break; case 10:cout<<"酉";break; case 11:cout<<"戌";break; case 12:cout<<"亥";break; default:;break; } switch( c ) { case 1:cout<<"鼠";break; case 2:cout<<"牛";break; case 3:cout<<"虎";break; case 4:cout<<"兔";break; case 5:cout<<"龙";break; case 6:cout<<"蛇";break; case 7:cout<<"马";break; case 8:cout<<"羊";break; case 9:cout<<"猴";break; case 10:cout<<"鸡";break; case 11:cout<<"狗";break; case 12:cout<<"猪";break; default:;break; } cout<<"年’。";
}
这篇关于干支、生肖查询器 v2.0的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!