计算员工总工资的 C 语言程序

如何用一个使用 Else If 语句的例子来编写一个计算员工总工资的 C 语言程序?这个程序可以帮助用户输入员工的任何基本工资,然后计算总工资。

为了演示 C 语言编程,我们使用以下 HRA 和 DA 百分比:

  • 如果基本工资小于或等于 10000,则 HRA = 基本工资的 8%,DA = 基本工资的 10%
  • 基本工资小于或等于 20000,则 HRA = 16%,DA = 20%
  • 基本工资大于 20000,则 HRA = 24%,DA = 30%

为了实现这一点,我们使用了 Else If 语句

#include <stdio.h>

int main()
{
float Basic, HRA, DA, Gross_Salary;

printf("\n Please Enter the Basic Salary of an Employee : ");
scanf("%f", &Basic);

if (Basic <= 10000)
{
HRA = (Basic * 8) / 100; // or HRA = Basic * (8 / 100)
DA = (Basic * 10) / 100; // Or Da= Basic * 0.1
}
else if (Basic <= 20000)
{
HRA = (Basic * 16) / 100;
DA = (Basic * 20) / 100;
}
else
{
HRA = (Basic * 24) / 100;
DA = (Basic * 30) / 100;
}
Gross_Salary = Basic + HRA + DA;
printf("\n Gross Salary of this Employee = %.2f", Gross_Salary);

return 0;
}
Program to Calculate Gross Salary of an Employee 1

让我尝试另一个金额

 Please Enter the Basic Salary of an Employee  :  35000

 Gross Salary of this Employee  =  53900.00

计算员工总工资的 C 语言程序

这个 C 语言程序允许用户输入基本工资、HRA 百分比和 DA 百分比。通过使用这些值,这个计算总工资或计算员工总工资的程序。

 #include <stdio.h>

int main()
{
char name[60];
float Basic, HRA_Per, DA_Per, HRA, DA, Gross_Salary;

printf("\n Please Enter the Employee Name : ");
gets(name);

printf(" Please Enter the Basic Salary of an Employee : ");
scanf("%f", &Basic);

printf(" Please Enter the HRA Percentage of an Employee : ");
scanf("%f", &HRA_Per);

printf(" Please Enter the DA Percentage of an Employee : ");
scanf("%f", &DA_Per);

HRA = Basic * (HRA_Per /100);
DA = Basic * (DA_Per / 100);

Gross_Salary = Basic + HRA + DA;
printf("\n Name = %s \n Basic Salary = %.2f \n HRA Amount = %.2f \n DA Amount = %.2f \n Gross Salary = %.2f", name, Basic, HRA, DA, Gross_Salary);

return 0;
}
 Please Enter the Employee Name  :  Tutorial Gateway
 Please Enter the Basic Salary of an Employee  :  35000
 Please Enter the HRA Percentage of an Employee  :  25
 Please Enter the DA Percentage of an Employee  :  35

 Name = Tutorial Gateway 
 Basic Salary = 35000.00 
 HRA Amount   = 8750.00 
 DA Amount   = 12250.00 
 Gross Salary = 56000.00

这个计算员工总工资的 程序 与上面的相同,但这次我们要求用户输入基本工资、HRA 金额和 DA 金额。

 #include <stdio.h>

int main()
{
char name[60];
float Basic, HRA, DA, Gross_Salary;

printf("\n Please Enter the Employee Name : ");
gets(name);

printf(" Please Enter the Basic Salary of an Employee : ");
scanf("%f", &Basic);

printf(" Please Enter the HRA Amount of an Employee : ");
scanf("%f", &HRA);

printf(" Please Enter the DA Amount of an Employee : ");
scanf("%f", &DA);

Gross_Salary = Basic + HRA + DA;

printf("\n Name = %s \n Basic Salary = %.2f \n HRA Amount = %.2f \n DA Amount = %.2f \n Gross Salary = %.2f", name, Basic, HRA, DA, Gross_Salary);

return 0;
}
 Please Enter the Employee Name  :  Tutorial Gateway
 Please Enter the Basic Salary of an Employee  :  25500
 Please Enter the HRA Amount of an Employee  :  4500
 Please Enter the DA Amount of an Employee  :  3200

 Name = Tutorial Gateway 
 Basic Salary = 25500.00 
 HRA Amount   = 4500.00 
 DA Amount   = 3200.00 
 Gross Salary = 33200.00