//通过输入生日判断星座
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
//通过生日判断星座
/** 出生月 */
int bir_month;
/** 出生日 */
int bir_day;
/** 星座二维数组 */
string constell_name[12][2] = {
{"魔羯座","水瓶座"},//一月
{"水瓶座","双鱼座"},//二月
{"双鱼座","白羊座"},//三月
{"白羊座","金牛座"},//四月
{"金牛座","双子座"},//五月
{"双子座","巨蟹座"},//六月
{"巨蟹座","狮子座"},//七月
{"狮子座","处女座"},//八月
{"处女座","天秤座"},//九月
{"天秤座","天蝎座"},//十月
{"天蝎座","射手座"},//十一月
{"射手座","魔羯座"},//十二月
};
/** 各月份跨星座日期 */
int constell_value[] = {20,19,21,20,21,22,23,23,23,24,23,22};
cout << "请输入出生日期( MM DD ): " ;
cin >> bir_month >> bir_day;
//确认星座一定是constell_name[][]格式,首先将输入的月份减去1就可以得到月份对应的两个星座
//然后通过与当月的星座分界线那天对比来判断具体是哪个星座,
//例如6月6号,确认第一个参数constell_name[6-1][],对应六月分界线constell_value[6-1]=22,由于6/22=0,故确认第二个参数constell_name[6-1][0],为双子座
cout << constell_name[bir_month - 1][bir_day / constell_value[bir_month - 1]];
return 0;
}
//程序输出
请输入出生日期( MM DD ): 11 16
天蝎座
Process returned 0 (0x0) execution time : 11.932 s
Press any key to continue.