Cprimerplus第七章第八题的代码

#include<iostream>
using namespace std;
#include<string.h>
void menu()
{
	cout << "******************************************************" << endl;
	char a[] = "1) $8.75/hr";
	char a1[] = "2) $9.33/hr";
	char a2[] = "3) $10.00/hr";
	char a3[] = "4) $11.20/hr";
	
	printf("%-40s", a);
	printf("%-40s\n", a1);
	printf("%-40s", a2);
	printf("%-40s\n", a3);
	cout << "*************输入5以结束此程序************************" << endl;
	cout << "******************************************************" << endl;
	cout << "*************请输入你的时薪标准***********************" << endl;
}
void jisuanji(float money,int hours)
{
	float zong=0;
	float tax=0;
	float jing=0;
	if(hours<=30)
	{
		zong=hours*money;
		tax=zong*0.15;
		jing=zong-tax;
	}else if(hours<=40)
	{
		zong=hours*money;
		if(zong>300){
			jing=300*0.85+(hours-30)*0.8;//这个课后参考答案错了,这个是正确的格式
		    tax=zong-jing;
		}else{
		tax=zong*0.15;
		jing=zong-tax;
		}
	}else{
		zong=money*40+(hours-40)*1.5*money;
		if(zong<=450)
		{
			tax=300*0.15+(zong-300)*0.2;
			jing=zong-tax;
		 } else{
		 	tax=300*0.15+150*0.2+(zong-450)*0.25;
		 	jing=zong-tax;
		 }
	}
	printf("您的税前工资是%.3f元,税后工资是%.3f元,交税%.3f元",zong,jing,tax);
}
int main(void)
{
	menu();
	int num;
	
	int hours;
	do
	{
		scanf("%d",&num);
		switch(num)
	{
		case 1:printf("请输入您的工作时间");
		       cin>>hours;jisuanji(8.75,hours);
		       break;
		case 2:printf("请输入您的工作时间");
		       cin>>hours;jisuanji(9.33,hours);
		       break;
		case 3:printf("请输入您的工作时间");
		       cin>>hours;jisuanji(10.00,hours);
		       break;
		case 4:printf("请输入您的工作时间");
		       cin>>hours;jisuanji(11.20,hours);
		       break;
		default :
			cout<<"请您重新尝试"<<endl;
			scanf("%d",num);
			break;
	}
	}while(num!=5);
}







上一篇:Directx11教程(47) alpha blend(4)-雾的实现


下一篇:一大波你可能不知道的 Linux 网络工具