最近在学C语言基础,在导师的指导下,先准备写个个税薪资计算器。这是一个简单的C语言小demo。主要用到了C语言的函数,if选择语句。
程序的主要代码如下(可运行):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
#include <stdio.h> float Salary; int len; float CulculateSalary (){ printf ( "请输入你的薪资\n" ); scanf ( "%f" ,&Salary); //getchar(); if (Salary -5000 <=3000 && Salary-5000>0) { Salary =Salary-(Salary-5000)*0.03; } else if (Salary -5000 >3000 && Salary-5000<=12000) { Salary =Salary-((Salary-5000)*0.1-210); } else if (Salary -5000 >12000 && Salary-5000<=25000) { Salary =Salary-((Salary-5000)*0.2-1410); } else if (Salary -5000 >25000 && Salary-5000<=35000) { Salary =Salary-((Salary-5000)*0.25-2660); } else if (Salary -5000 >35000 && Salary-5000<=55000) { Salary =Salary-((Salary-5000)*0.3-4410); } else if (Salary -5000 >55000 && Salary-5000<=80000) { Salary =Salary-((Salary-5000)*0.35-7160); } else if (Salary -5000 >80000) { Salary =Salary-((Salary-5000)*0.45-15160); } else { Salary= Salary- Salary *0; } return Salary; } int main(){ // CulculateSalary(7000); printf ( "请输入查税薪资的个数\n" ); scanf ( "%d" ,&len); for ( int i=0;i<len;i++){ float realSalary = CulculateSalary(); printf ( "最终薪资%.2f\n" ,Salary); } return 0; } |
运行的环境是vscode,编译运行的结果如下:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/weixin_42952472/article/details/118569188