作者在 2011-09-16 20:27:03 发布以下内容
#include <stdio.h>
#define YJ 8.75
#define EJ 9.33
#define SJ 10.00
#define SIJ 11.20
#define JBSL 0.15
#define EJSL 0.2
#define ZJSL 0.25
char get_first(void);
int main(void)
{
int i,num,hours;
float hmoney,money,shui,jing;
#define YJ 8.75
#define EJ 9.33
#define SJ 10.00
#define SIJ 11.20
#define JBSL 0.15
#define EJSL 0.2
#define ZJSL 0.25
char get_first(void);
int main(void)
{
int i,num,hours;
float hmoney,money,shui,jing;
printf("******************************************************\n");
printf("Enter the number corresponding to the desired pay rate or action:\n");
printf("a)$8.75美元\t\t\tb)$9.33美元\nc)$10.00美元\t\t\td)$11.20美元\nq)quit\n");
printf("******************************************************\n");
num = get_first();
while(num != 'q')
{
switch(num)
{
case 'a':
hmoney = YJ;
break;
case 'b':
hmoney = EJ;
break;
case 'c':
hmoney = SJ;
break;
case 'd':
hmoney = SIJ;
break;
default:
goto back;
}
printf("Please enter your workhours in a week:");
while(i = scanf("%d",&hours))
{
if( i != 1)
{
goto back;
}
else
{
money = 0;
jing = 0;
if(hours <= 40)
{
money = hours * hmoney;
if(money <= 300)
shui = money * JBSL;
else
shui = 300 * JBSL +(money - 300) * EJSL;
}
else if(hours <= 168)
{
money = (40 + (hours -40) * 1.5) * hmoney;
if(money <= 450)
shui = 300 * JBSL + (money - 300) * EJSL;
else
shui = 300 * JBSL + 150 * EJSL + (money - 450) * ZJSL;
}
else
{
printf("A week is total 168 hours!\n");
break;
}
jing = money - shui;
printf("This week the total money is %.2f,shuijin is %.2f,the last is %.2f.\n",money,shui,jing);
printf("The last weekhours is( > 168 to quit):");
}
}
back:printf("a)$8.75美元\t\t\tb)$9.33美元\nc)$10.00美元\t\t\td)$11.20美元\nq)quit\n");
printf("Please enter your chose again:\n");
num = get_first();
}
return 0;
}
char get_first(void)
{
int ch;
printf("Enter the number corresponding to the desired pay rate or action:\n");
printf("a)$8.75美元\t\t\tb)$9.33美元\nc)$10.00美元\t\t\td)$11.20美元\nq)quit\n");
printf("******************************************************\n");
num = get_first();
while(num != 'q')
{
switch(num)
{
case 'a':
hmoney = YJ;
break;
case 'b':
hmoney = EJ;
break;
case 'c':
hmoney = SJ;
break;
case 'd':
hmoney = SIJ;
break;
default:
goto back;
}
printf("Please enter your workhours in a week:");
while(i = scanf("%d",&hours))
{
if( i != 1)
{
goto back;
}
else
{
money = 0;
jing = 0;
if(hours <= 40)
{
money = hours * hmoney;
if(money <= 300)
shui = money * JBSL;
else
shui = 300 * JBSL +(money - 300) * EJSL;
}
else if(hours <= 168)
{
money = (40 + (hours -40) * 1.5) * hmoney;
if(money <= 450)
shui = 300 * JBSL + (money - 300) * EJSL;
else
shui = 300 * JBSL + 150 * EJSL + (money - 450) * ZJSL;
}
else
{
printf("A week is total 168 hours!\n");
break;
}
jing = money - shui;
printf("This week the total money is %.2f,shuijin is %.2f,the last is %.2f.\n",money,shui,jing);
printf("The last weekhours is( > 168 to quit):");
}
}
back:printf("a)$8.75美元\t\t\tb)$9.33美元\nc)$10.00美元\t\t\td)$11.20美元\nq)quit\n");
printf("Please enter your chose again:\n");
num = get_first();
}
return 0;
}
char get_first(void)
{
int ch;
while((ch = getchar()) == ' ')
continue;
while(getchar() != '\n')
continue;
return ch;
}
程序完成后,总有一些小问题,当用户输入大于168小时后,重新选择a~b,q的时候,程序不能读取用户输入?很闹心啊!
continue;
while(getchar() != '\n')
continue;
return ch;
}
程序完成后,总有一些小问题,当用户输入大于168小时后,重新选择a~b,q的时候,程序不能读取用户输入?很闹心啊!