gpt4 book ai didi

有人能告诉我我的错误在哪里吗?我的程序给出了错误的输出

转载 作者:行者123 更新时间:2023-11-30 18:55:44 25 4
gpt4 key购买 nike

/*3。编写一个程序来计算 10 名员工的净工资。使用函数执行以下任务:-A。读入 10 名员工的总工资。b.计算每个员工的净工资。C。以表格形式显示每个员工的总工资和净工资。例如:-

工资总额 工资 Netty 2000 18203000 2720*/

//计算10名员工的净工资并显示

#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_);
}

最佳答案

打开警告:

error: lvalue required as left operand of assignment

问题是您正在尝试为函数赋值。

改变

displaysalary = (salary[i],netsalary[i]);

displaysalary(salary[i],netsalary[i]);

另一方面(正如 Tim Seguine 所指出的)你正在混合整数和 float

int netsalary;
netsalary= pay-(pay*0.1);//formula to calculate the net salary

更改为

netsalary= pay-(pay/10);//formula to calculate the net salary

关于有人能告诉我我的错误在哪里吗?我的程序给出了错误的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26703071/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com