switch用对了吗?
#include<stdio.h>#define BASEERS 40
#define OVERTIMES 1.5
#define AMT1 300
#define AMT2 150
#define RATE1 0.15
#define RATE2 0.2
#define RATE3 0.25
int main()
{
double sum,tax,net,hr,hours;
int a;
printf("enter the number corresponding to the desired pay rate or action:\n");
printf("1)$8.75/hr 2)$9.33/hr\n");
printf("3)$10.00/hr 4)$11.20/hr\n");
printf("5)quit;\n");
while((scanf("%d",&a))==1)
{
switch(a)
{
case '1':
hr=8.75;
break;
case '2':
hr=9.33;
break;
case '3':
hr=10.00;
break;
case '4':
hr=11.20;
break;
case '5':
hr=0.0;
break;
default:
hr=1.0;
}
if(hr==1.0)
{
printf("it's error,please enter a number from 1 to 5.\n");
continue;
}
else if(hr==0.0)
break;
else
{
printf("please enter the number of hours worked this hours.\n");
scanf("%f",&hours);
if(hours<=BASEERS)
sum=hours*hr;
else
sum=hr*BASEERS+hr*(hours-BASEERS)*OVERTIMES;
if(sum<AMT1)
{
tax=sum*RATE1;
net=sum-tax;
}
else if(sum<(AMT1+AMT2))
{
tax=AMT1*RATE1+(sum-AMT1)*RATE2;
net=sum-tax;
}
else
{
tax=AMT1*RATE1+AMT2*RATE2+(sum-AMT1-AMT2)*RATE3;
net=sum-tax;
}
}
printf("sum is %.2f,tax is %.2f,net is %.2f.\n",sum,tax,net);
}
return 0;
}
为什么按1-5,会出来it's error,please enter a number from 1 to 5。想不通,跪求指导啊