/ * 3。编写一个程序来计算10名员工的净工资。使用功能执行以下任务: - 一个。读入10名员工的工资总额。 湾计算每位员工的净工资。 C。以表格形式显示每位员工的工资总额和净工资。例如: -
工资总薪资 2000 1820 3000 2720 * /
//为10名员工计算netsalary并显示
#include<stdio.h>
int readSalary();
int Calculatenet(int);
void displaysalary(int,int);
int main()
{
int i,salary[10],netsalary[10] ;
for(i=0;i<10;i++)
{
salary[i]=readSalary(); /*for each and every element in the array, the value is entered*/
netsalary[i]=Calculatenet(salary[i]); /*the value is passed into the function*/
displaysalary=(salary[i],netsalary[i]); /*to display the results, the values frm both function are passed in*/
} /*A bit confused about passing in arrays in this form. Pls correct me.*/
return 0;
}
int readSalary()
{
int salary;
printf("Enter your gross salary:");
scanf("%d",&salary);
return salary;
}
int Calculatenet(int pay)
{
int netsalary;
netsalary= pay-(pay*0.1);//formula to calculate the net salary
return netsalary;
}
void displaysalary(int pay_, int netsalary_)
{
printf("Gross salary\t Net Salary\n");
printf("%d\t %d\n",pay_,netsalary_);
}
答案 0 :(得分:2)
启用警告:
error: lvalue required as left operand of assignment
问题是您正在尝试为函数赋值。
更改
displaysalary = (salary[i],netsalary[i]);
到
displaysalary(salary[i],netsalary[i]);
另一方面(正如Tim Seguine指出的那样)你正在混合整数和浮点数
int netsalary;
netsalary= pay-(pay*0.1);//formula to calculate the net salary
更改为
netsalary= pay-(pay/10);//formula to calculate the net salary