如何在C语言程序中添加这个功能(输入Y\N继续或结束程序计算)现在写的程序计算后随便按下键盘会结束程序
要是在计算有得从新执行感觉太麻烦了但是我是初学者请教下高手这是我的程序#include<stdio.h>voidmain(){inta,c;floatb,z=0;prin...
要是在计算有得从新执行感觉太麻烦了 但是我是初学者请教下高手这是我的程序#include <stdio.h>
void main()
{
int a,c;
float b,z=0;
printf("输入工资(元):");
scanf("%d",&a);
b=a-2000;
if(b<=500)
c=1;
else
if(b<=2000)
c=2;
else
if(b<=5000)
c=3;
else
if(b<=20000)
c=4;
else
if(b<=40000)
c=5;
else
if(b<=60000)
c=6;
else
if(b<=80000)
c=7;
else
if(b<=100000)
c=8;
else
if(b<=9998000)
c=9;
switch(c)
{
case 1:z=b*0.05;break;
case 2:z=b*0.10-25;break;
case 3:z=b*0.15-125;break;
case 4:z=b*0.20-375;break;
case 5:z=b*0.25-1375;break;
case 6:z=b*0.30-3375;break;
case 7:z=b*0.35-6375;break;
case 8:z=b*0.40-10375;break;
case 9:z=b*0.45-15375;break;
}
printf("应缴税为:%f\n",z);
} 展开
void main()
{
int a,c;
float b,z=0;
printf("输入工资(元):");
scanf("%d",&a);
b=a-2000;
if(b<=500)
c=1;
else
if(b<=2000)
c=2;
else
if(b<=5000)
c=3;
else
if(b<=20000)
c=4;
else
if(b<=40000)
c=5;
else
if(b<=60000)
c=6;
else
if(b<=80000)
c=7;
else
if(b<=100000)
c=8;
else
if(b<=9998000)
c=9;
switch(c)
{
case 1:z=b*0.05;break;
case 2:z=b*0.10-25;break;
case 3:z=b*0.15-125;break;
case 4:z=b*0.20-375;break;
case 5:z=b*0.25-1375;break;
case 6:z=b*0.30-3375;break;
case 7:z=b*0.35-6375;break;
case 8:z=b*0.40-10375;break;
case 9:z=b*0.45-15375;break;
}
printf("应缴税为:%f\n",z);
} 展开
3个回答
展开全部
#include <stdio.h>
void main()
{
int a,c;
char flag='y';
float b,z=0;
while(flag=='y'||flag=='Y'){
printf("输入工资(元):");
scanf("%d",&a);
b=a-2000;
if(b<=500)
c=1;
else
if(b<=2000)
c=2;
else
if(b<=5000)
c=3;
else
if(b<=20000)
c=4;
else
if(b<=40000)
c=5;
else
if(b<=60000)
c=6;
else
if(b<=80000)
c=7;
else
if(b<=100000)
c=8;
else
if(b<=9998000)
c=9;
switch(c)
{
case 1:z=b*0.05;break;
case 2:z=b*0.10-25;break;
case 3:z=b*0.15-125;break;
case 4:z=b*0.20-375;break;
case 5:z=b*0.25-1375;break;
case 6:z=b*0.30-3375;break;
case 7:z=b*0.35-6375;break;
case 8:z=b*0.40-10375;break;
case 9:z=b*0.45-15375;break;
}
printf("应缴税为:%f\n",z);
printf("要继续输入?:(Y\\N)\n");
scanf(" %c",&flag);
}
}
void main()
{
int a,c;
char flag='y';
float b,z=0;
while(flag=='y'||flag=='Y'){
printf("输入工资(元):");
scanf("%d",&a);
b=a-2000;
if(b<=500)
c=1;
else
if(b<=2000)
c=2;
else
if(b<=5000)
c=3;
else
if(b<=20000)
c=4;
else
if(b<=40000)
c=5;
else
if(b<=60000)
c=6;
else
if(b<=80000)
c=7;
else
if(b<=100000)
c=8;
else
if(b<=9998000)
c=9;
switch(c)
{
case 1:z=b*0.05;break;
case 2:z=b*0.10-25;break;
case 3:z=b*0.15-125;break;
case 4:z=b*0.20-375;break;
case 5:z=b*0.25-1375;break;
case 6:z=b*0.30-3375;break;
case 7:z=b*0.35-6375;break;
case 8:z=b*0.40-10375;break;
case 9:z=b*0.45-15375;break;
}
printf("应缴税为:%f\n",z);
printf("要继续输入?:(Y\\N)\n");
scanf(" %c",&flag);
}
}
展开全部
void main()
{
begin:
int a,c;
float b,z=0;
printf("输入工资(元):");
scanf("%d",&a);
b=a-2000;
if(b<=500)
c=1;
else
if(b<=2000)
c=2;
else
if(b<=5000)
c=3;
else
if(b<=20000)
c=4;
else
if(b<=40000)
c=5;
else
if(b<=60000)
c=6;
else
if(b<=80000)
c=7;
else
if(b<=100000)
c=8;
else
if(b<=9998000)
c=9;
switch(c)
{
case 1:z=b*0.05;break;
case 2:z=b*0.10-25;break;
case 3:z=b*0.15-125;break;
case 4:z=b*0.20-375;break;
case 5:z=b*0.25-1375;break;
case 6:z=b*0.30-3375;break;
case 7:z=b*0.35-6375;break;
case 8:z=b*0.40-10375;break;
case 9:z=b*0.45-15375;break;
}
printf("应缴税为:%f\n",z);
printf("是否继续计算:");
char input = getchar();
if(input == 'y' || input == 'Y')
goto begin;
else if(input == 'n' || input == 'N')
;
else
;
}
{
begin:
int a,c;
float b,z=0;
printf("输入工资(元):");
scanf("%d",&a);
b=a-2000;
if(b<=500)
c=1;
else
if(b<=2000)
c=2;
else
if(b<=5000)
c=3;
else
if(b<=20000)
c=4;
else
if(b<=40000)
c=5;
else
if(b<=60000)
c=6;
else
if(b<=80000)
c=7;
else
if(b<=100000)
c=8;
else
if(b<=9998000)
c=9;
switch(c)
{
case 1:z=b*0.05;break;
case 2:z=b*0.10-25;break;
case 3:z=b*0.15-125;break;
case 4:z=b*0.20-375;break;
case 5:z=b*0.25-1375;break;
case 6:z=b*0.30-3375;break;
case 7:z=b*0.35-6375;break;
case 8:z=b*0.40-10375;break;
case 9:z=b*0.45-15375;break;
}
printf("应缴税为:%f\n",z);
printf("是否继续计算:");
char input = getchar();
if(input == 'y' || input == 'Y')
goto begin;
else if(input == 'n' || input == 'N')
;
else
;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include<stdio.h>
#include<string.h>
void main()
{
int a,c;
char d;
float b,z=0;
while(1)
{
printf("输入工资(元):");
scanf("%d",&a);fflush(stdin);
b=a-2000;
if(b<=500)
c=1;
else
if(b<=2000)
c=2;
else
if(b<=5000)
c=3;
else
if(b<=20000)
c=4;
else
if(b<=40000)
c=5;
else
if(b<=60000)
c=6;
else
if(b<=80000)
c=7;
else
if(b<=100000)
c=8;
else
if(b<=9998000)
c=9;
switch(c)
{
case 1:z=b*0.05;break;
case 2:z=b*0.10-25;break;
case 3:z=b*0.15-125;break;
case 4:z=b*0.20-375;break;
case 5:z=b*0.25-1375;break;
case 6:z=b*0.30-3375;break;
case 7:z=b*0.35-6375;break;
case 8:z=b*0.40-10375;break;
case 9:z=b*0.45-15375;break;
}
printf("应缴税为:%f\n",z);
printf("Y:继续;N结束\n");
scanf("%c",&d);
fflush(stdin);
if(d=='N'||d=='n')
break;
}
}
#include<string.h>
void main()
{
int a,c;
char d;
float b,z=0;
while(1)
{
printf("输入工资(元):");
scanf("%d",&a);fflush(stdin);
b=a-2000;
if(b<=500)
c=1;
else
if(b<=2000)
c=2;
else
if(b<=5000)
c=3;
else
if(b<=20000)
c=4;
else
if(b<=40000)
c=5;
else
if(b<=60000)
c=6;
else
if(b<=80000)
c=7;
else
if(b<=100000)
c=8;
else
if(b<=9998000)
c=9;
switch(c)
{
case 1:z=b*0.05;break;
case 2:z=b*0.10-25;break;
case 3:z=b*0.15-125;break;
case 4:z=b*0.20-375;break;
case 5:z=b*0.25-1375;break;
case 6:z=b*0.30-3375;break;
case 7:z=b*0.35-6375;break;
case 8:z=b*0.40-10375;break;
case 9:z=b*0.45-15375;break;
}
printf("应缴税为:%f\n",z);
printf("Y:继续;N结束\n");
scanf("%c",&d);
fflush(stdin);
if(d=='N'||d=='n')
break;
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询