C语言问题
本帖最后由 728252187 于 2020-10-8 16:59 编辑#include <stdio.h>
#define RATE1 0.15//没超出部份的税率
#define RATE2 0.28// 超出部份的税率
int main(void)
{
double pay;//用户的工资额度
double taxes;//用户是要交的税金额度
int num = 2;//婚姻对应的数字
double BASE;
float number;
do
{
printf("_____________________________________________________________________\n");
printf("%-34s|%-34s|\n","类别","税金");
printf("_____________________________________________________________________\n");
printf("(1)%-31s|%-34s|\n","单身","17850美元按15%计,超出部分按28%计");
printf("_____________________________________________________________________\n");
printf("(2)%-31s|%-34s|\n","户主","23900美元按15%计,超出部分按28%计");
printf("_____________________________________________________________________\n");
printf("(3)%-31s|%-34s|\n","已婚,共有","29750美元按15%计,超出部分按28%计");
printf("_____________________________________________________________________\n");
printf("(4)%-31s|%-34s|\n","已婚,离异","14875美元按15%计,超出部分按28%计");
printf("_____________________________________________________________________\n");
printf("Please enter the number corresponding to your marital status:\n");
printf("the number 5 is quite\n");
if ( num < 1 || num > 5)
{
printf("ERROR :Please enter a number 1~5: ");
}
scanf("%d", &num);
} while (num < 1 || num > 5);
while(num != 5)
{
switch (num) //根据输入来初始化每小时的工资
{
case 1 : BASE = 17850;
break;
case 2 : BASE = 23900;
break;
case 3 : BASE = 29750;
break;
case 4 : BASE = 14875;
}
printf("Please enter your income :\n");
scanf("%lf", &pay);
while (pay <= 0)
{
printf("invalid value please enter your income : \n");
scanf("%lf", &pay);
}
if (pay <= BASE)
{
taxes = pay * RATE1;
}
else if (pay >= BASE)
{
taxes = BASE * RATE1 +(pay-BASE) * RATE2;
}
}
printf("The tax you have to pay is $%.2lf\n",taxes);
printf("Please enter the number corresponding to your marital status:\n");
scanf("%d",&num);
return 0;
}
到底哪儿错了怎么一直在Please enter your income: 这里循环程序执行不下去? #include <stdio.h>
#define RATE1 0.15//没超出部份的税率
#define RATE2 0.28// 超出部份的税率
int main(void)
{
double pay;//用户的工资额度
double taxes;//用户是要交的税金额度
int num = 2;//婚姻对应的数字
double BASE;
float number;
do
{
printf("_____________________________________________________________________\n");
printf("%-34s|%-34s|\n","类别","税金");
printf("_____________________________________________________________________\n");
printf("(1)%-31s|%-34s|\n","单身","17850美元按15%计,超出部分按28%计");
printf("_____________________________________________________________________\n");
printf("(2)%-31s|%-34s|\n","户主","23900美元按15%计,超出部分按28%计");
printf("_____________________________________________________________________\n");
printf("(3)%-31s|%-34s|\n","已婚,共有","29750美元按15%计,超出部分按28%计");
printf("_____________________________________________________________________\n");
printf("(4)%-31s|%-34s|\n","已婚,离异","14875美元按15%计,超出部分按28%计");
printf("_____________________________________________________________________\n");
printf("Please enter the number corresponding to your marital status:\n");
printf("the number 5 is quite\n");
if ( num < 1 || num > 5)
{
printf("ERROR :Please enter a number 1~5: ");
}
scanf("%d", &num);
} while (num < 1 || num > 5);
while(num != 5)
{
switch (num) //根据输入来初始化每小时的工资
{
case 1 : BASE = 17850;
break;
case 2 : BASE = 23900;
break;
case 3 : BASE = 29750;
break;
case 4 : BASE = 14875;
}
} //while应该在这里结束 ,其实感觉whule(num != 5)是多余的
printf("Please enter your income :\n");
scanf("%lf", &pay);
while (pay <= 0)
{
printf("invalid value please enter your income : \n");
scanf("%lf", &pay);
}
if (pay <= BASE)
{
taxes = pay * RATE1;
}
else if (pay >= BASE)
{
taxes = BASE * RATE1 +(pay-BASE) * RATE2;
}
printf("The tax you have to pay is $%.2lf\n",taxes);
printf("Please enter the number corresponding to your marital status:\n");
scanf("%d",&num);
return 0;
} 1、第11行定义的 float number; 程序中没有使用;
2、循环不止的原因是:while(num != 5),只要 num 不等于 5 这个条件不满足(也就是说,只有 num = 5 才会停止循环),循环就一定会继续的 巴巴鲁 发表于 2020-10-8 17:28
嗯,把while(num!=5)程序可以运行了,谢谢。
页:
[1]