70,021
社区成员




#include <stdio.h>
#define SINGLE 17850
#define HOST 23900
#define MARRIED 29750
#define MARRIED_DIVORCE 14875
#define RATE1 0.15
#define RATE2 0.28
int main(void)
{
char choice;
int threshold;
double salary,tax;
while(1)
{
printf("Please input your choice\n");
printf("1)SINGLE\t\t2)HOST\n");
printf("3)MARRIED\t\t4)MARRIED_DIVORCE\n");
printf("5)quit\n");
scanf("%c",&choice);
switch(choice)
{
case '1':threshold=SINGLE;break;
case '2':threshold= HOST;break;
case '3':threshold=MARRIED;break;
case '4':threshold=MARRIED_DIVORCE;break;
case '5':printf("quit\n");return 0;
default:continue;
}
printf("You have chose %c\n",choice);
printf("Please input your salary\n");
scanf("%lf",&salary);
if(salary<= threshold) tax=salary* RATE1;
else tax= threshold* RATE1+(salary-threshold)* RATE2;
printf("Tax is %lf\n",tax);
printf("hello world\n");
}
}
#include <stdio.h>
#include <stdlib.h>
#define SINGLE 17850
#define HOST 23900
#define MARRIED 29750
#define MARRIED_DIVORCE 14875
#define RATE1 0.15
#define RATE2 0.28
int main()
{
static char choice[1024];
int threshold;
double salary,tax;
while(1)
{
puts("Please input your choice\n"
"1)SINGLE\t\t2)HOST\n"
"3)MARRIED\t\t4)MARRIED_DIVORCE\n"
"5)quit\n");
scanf("%1023s",choice);
switch(atoi(choice))
{
case 1:
threshold=SINGLE;
break;
case 2:threshold= HOST;
break;
case 3:
threshold=MARRIED;
break;
case 4:
threshold=MARRIED_DIVORCE;
break;
case 5:
printf("quit\n");
return 0;
default:
printf("Invalid choice: %s\n",choice);
continue;
}
printf("Please input your salary\n");
scanf("%lf",&salary);
if(salary<= threshold)
{
tax=salary* RATE1;
}
else
{
tax= threshold* RATE1+(salary-threshold)* RATE2;
}
printf("Tax is %lf\n",tax);
}
return 0;
}