- #include "stdafx.h"
- #include "stdio.h"
- bool BaIn(int Age1 ,char Sex1,char Marry1,int Child1)
- {
- if ((Age1 < 1 )||(Age1 > 99))
- {
- printf("请输入有效的年龄段(1-99之间):/n");
- }
- else if ((Sex1 != 'F')&&(Sex1 != 'M'))
- {
- printf("请输入合法的字符(F(女) or M(男)):/n");
- return true;
- }
- else if ((Marry1 != 'Y')&&(Marry1 != 'N'))
- {
- printf("请输入合法的婚姻状况(Y已婚,N未婚):/n");
- return true;
- }
- else if (((Child1 >9)||(Child1 < 0)))
- {
- printf("请输入合法的抚养人数(数字0-9):/n");
- return true;
- }
- return false;
- }
- int main(int argc, char* argv[])
- {
- //保费 = 投保额*保险费率;
- int Age,Child,APoint,BPoint,CPoint,DPoint,SumPoint;
- char Sex,Marry;
- float HL;
- printf("请输入你要的保险费用的基本信息:/n");
- do
- {
- scanf("%d,%c,%c,%d",&Age,&Sex,&Marry,&Child);
- }while (BaIn(Age,Sex,Marry,Child));
- if ((Age >= 20)&&(Age <= 39))
- {
- APoint = 6;
- }
- else
- {
- if ((Age >= 40)&&(Age <= 59))
- {
- APoint = 4;
- }
- else
- APoint = 2;
- }
- if (Sex = 'M')
- {
- BPoint = 5;
- }
- else
- {
- BPoint = 3;
- }
- if (Marry = 'Y')
- {
- CPoint = 3;
- }
- else
- {
- CPoint = 5;
- }
- DPoint = (int)Child*0.5;
- if (DPoint == 3)
- {
- DPoint = 3;
- }
- SumPoint = APoint +BPoint + CPoint -DPoint;
- if (SumPoint >= 10)
- {
- HL = 0.006;
- }
- else
- {
- HL = 0.001;
- }
- printf("年龄:%d,性别:%c,婚姻状况:%c,抚养人数:%d/n",Age,Sex,Marry,Child);
- printf("保险费率%f/n",HL);
- return 0;
- }