當前位置:首頁 » 編程語言 » c語言計稅
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

c語言計稅

發布時間: 2023-08-23 18:54:59

Ⅰ 求各位大神幫幫忙 c語言怎樣使用switch語句來寫工資提成

#include<stdio.h>
intmain()
{
floata,b;
printf("請輸入銷售額:");
scanf("%f",&a);
switch((int)(a/1000))//提取a的千位數字
{
case0:
b=0;
break;
case1:
b=2;
break;
case2:
case3:
case4:
b=5;
break;
default:
if(a==5000.0)//邊界情況:銷售額等於5000元
b=5;
else
b=10;
break;
}
floattotal=500+500*(b/100);
printf("總工資為:%.2f ",total);
return0;
}

示範對話1:

Ⅱ c語言編寫程序,輸入月薪數a,計算並輸出稅率、應繳稅款和實得獎金數。工薪所得扣除標

#include <stdio.h>
main()
{
int grade;
float salary,real_salary,ratal,tax;
printf("請輸入個人工資薪金所得:\n ");
scanf("%f", &salary);
if(salary<0)
{
printf("輸入的數據錯誤\n");
ratal=0;
tax=0;
}
else if(salary<=2000)
{
ratal=0;
tax=0;
}
else
ratal=salary-2000;
if(ratal<=500)
grade=1;
if(ratal>500 && ratal<=2000)
grade=2;
if(ratal>2000 && ratal<=5000)
grade=3;
if(ratal>5000 && ratal<=20000)
grade=4;
if(ratal>20000 && ratal<=40000)
grade=5;
if(ratal>40000 && ratal<=60000)
grade=6;
if(ratal>60000 && ratal<=80000)
grade=7;
if(ratal>80000 && ratal<=100000)
grade=8;
switch (grade)
{
case 1:tax=ratal*0.05-0;break;
case 2:tax=ratal*0.1-25;break;
case 3:tax=ratal*0.15-125;break;
case 4:tax=ratal*0.2-375;break;
case 5:tax=ratal*0.25-1375;break;
case 6:tax=ratal*0.3-3375;break;
case 7:tax=ratal*0.35-6375;break;
case 8:tax=ratal*0.4-10375;break;
default: tax=ratal*0.45-15375;
}
real_salary=salary-tax;
printf("應納稅額: %.2f元\n",tax);
printf("稅後月收入: %.2f元\n",real_salary);
}

Ⅲ C語言計算工資的代碼

源代碼中,你的if語句裡面兩個表達式是用逗號分開的,這樣並不能滿足兩個條件都滿足的要求
現修改代碼如下,

#include<stdio.h>
intmain()
{
inty,t;
doublem;
scanf("%d%d",&y,&t);
if(y<5&&t<=40)//使用&&表示要求兩個條件都滿足
printf("%.2f",m=t*30);
elseif(y<5&&t>40)
printf("%.2f",m=40*30+(t-40)*30*1.5);
elseif(y>=5&&t<=40)
printf("%.2f",m=t*50);
else
printf("%.2f",m=40*50+(t-40)*50*1.5);
}