gpt4 book ai didi

c - 错误 : invalid lvalue in assignment [in c]

转载 作者:行者123 更新时间:2023-12-02 06:00:43 25 4
gpt4 key购买 nike

找不到问题所在...

我一直在编程并试图解决这里的问题,但我找不到错误。你们能帮我指点一下我在这个程序中写错了什么吗?将不胜感激:)

这是我编译程序后编译器说的:

In function 'main':
Line 40: error: invalid lvalue in assignment

这是:

/*Calculate area for single room*/
width * length = totalArea_single;

完整代码如下:

#include <stdio.h>
#include <stdlib.h>

/*Main function of this program*/
int main()
{
char input[512];/*buffer*/
char roomInput[512];/*buffer*/
int roomCount =0;/*Store number of room*/
int width =0;/*width integer*/
int length =0;/*length integer*/
int room =0;/*To make sure roomCount have to be more than 0*/
int totalArea_single =0;
int totalArea_all =0;

/*Ask how many room in the house*/
printf("\nHow many rooms in the house?: ");
fgets(input,sizeof(input),stdin);
sscanf(input,"%d",&roomCount);

/*For loop for calculating room area by number of room entered*/
for(room=0;room<roomCount;room++)
{
/*Input for width and have to be more than 0*/
while(width>0)
{
printf("Width in meters for room %d: ",room+1);
fgets(roomInput,sizeof(roomInput),stdin);
sscanf(roomInput,"%d",&width);
}

/*Input for length and have to be more than 0*/
while(length>0)
{
printf("Length in meters for room %d: ",room+1);
fgets(roomInput,sizeof(roomInput),stdin);
sscanf(roomInput,"%d",&length);
}

/*Calculate area for single room*/
width * length = totalArea_single;

/*Store area of all rooms*/
totalArea_all = totalArea_single + totalArea_all;

width = -1;
length = -1;
}

/*Print out total areas of the house*/
printf("\nTotal areas of the house is %d square meters",totalArea_all);

return 0;
}

我不确定我做错了什么...感谢您的帮助:)

最佳答案

应该是

totalArea_single = width * length;

代替

width * length = totalArea_single;

关于c - 错误 : invalid lvalue in assignment [in c],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25832771/

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