// ConsoleApplication2.cpp: 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <stdio.h>
#include<string.h>
#include<stdlib.h>
char ch;
#define A "Enter the number corresponding to the desired pay rate or action:"
#define tax1 0.15
#define tax2 0.20
#define tax3 0.25
#define state1 300*0.15
#define state2 150*0.25
void ShowTheManu();
int caculate(int,int);
const float BasicSalary[] = { 8.75f,9.33f,10.00f,11.20f };
char info[40];
int quit = 0;
int RequestTime();
int main()
{
ShowTheManu();
while (quit != 1)
{
ch = getchar();
scanf_s("%*[^\n]%*c");
if (iswdigit(ch) && ch > '0' && ch <= '5')
{
switch(ch)
{
case '1':
caculate(RequestTime(),atoi(&ch));
printf("%s\n", info);
getchar();
ShowTheManu();
break;
case '2':
caculate(RequestTime(),atoi(&ch));
printf("%s\n", info);
getchar();
ShowTheManu();
break;
case '3':
caculate(RequestTime(),atoi(&ch));
printf("%s\n", info);
getchar();
ShowTheManu();
break;
case '4':
caculate(RequestTime(),atoi(&ch));
printf("%s\n", info);
getchar();
ShowTheManu();
break;
case '5':
quit = 1;
break;
}
}
else
{
printf("please enter a opction among above\n");
ShowTheManu();
}
}
}
void ShowTheManu()
{
for (unsigned int count = 0; count < strlen(A); count++)
printf("*");
printf("\n\n");
printf("%s\n", A);
printf("1) $%2.2f/hr 2) $%2.2f/hr\n"
"3) $%2.2f/hr 4) $%2.2f/hr\n"
"5) quit\n", BasicSalary[0],BasicSalary[1],BasicSalary[2],BasicSalary[3]);
for (unsigned int count = 0; count < strlen(A); count++)
printf("*");
printf("\n");
}
int caculate(int n,int a)
{
float sum;
float after;
float tax;
if ((n - 40) > 0)
sum = BasicSalary[a - 1] * 1.5f*n;
else
sum = BasicSalary[a - 1] * n;
if (sum <= 300)
tax = (float)(sum * tax1);
else if (sum <= 450)
tax = (float)(state1 + (sum - 300) * tax2);
else
tax = (float)(state1 + state2 + (sum - 450)* tax3);
after = sum - tax;
sprintf_s(info, "total:%6.2f tax:%6.2f pure:%6.2f", sum, tax, after);
return 0;
}
int RequestTime()
{
int t;
while (1)
{
printf("please enter your work time(by hours)\n");
if (scanf_s("%d", &t) == 0 || t <= 0)
{
printf("please enter a right time(by hours)\n");
scanf_s("%*[^\n]%*c");
}
else
break;
}
return t;
}