gpt4 book ai didi

C2106 : '=' : left operand must be l-value

转载 作者:行者123 更新时间:2023-11-30 21:00:23 25 4
gpt4 key购买 nike

所以,我正在学习 C 作为我的第一语言,并且在进行一些编码练习时,我遇到了上述错误。我按照书上所说的做了一切(Stephen G. Kochan:C 语言编程,第三版)。我究竟做错了什么?我使用的是 Microsoft Visual Studio 2015。

感谢您的帮助!标记

struct date
{
int month;
int day;
int year;
};

int main(void)
{
struct date today, tomorrow;
int numberOfDays(struct date d);

printf("Adja meg a mai datumot (hh nn eeee): ");
scanf_s("%i%i%i", &today.month, &today.day, &today.year);

if (today.day != numberOfDays(today))
{
tomorrow.day = today.day + 1;
tomorrow.month = today.month;
tomorrow.year = today.year;
}
else if (today.month == 12)
{
tomorrow.day = 1;
tomorrow.month = 1;
tomorrow.year = today.year + 1;
}
else
{
tomorrow.day = 1;
tomorrow.month = today.month + 1;
tomorrow.year = today.year;
}
printf("A holnapi datum: %i/%i/%.2i.\n", tomorrow.month, tomorrow.day, tomorrow.year % 100);

return 0;
}

int numberOfDays(struct date d)
{
int days;
bool isLeapYear(struct date d);
const int daysPerMonth[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

if (isLeapYear(d) == true && d.month == 2)
days = 29;
else
days = daysPerMonth[d.month - 1];

return days;
}

bool isLeapYear(struct date d)
{
bool leapYearFlag;

if ( (d.year % 4 == 0 && d.year % 100 = 0) || d.year % 400 == 00) //The error shows up here
leapYearFlag = true;
else
leapYearFlag = false;

return leapYearFlag;
}

最佳答案

这里有一个错别字

if ( (d.year % 4 == 0 && d.year % 100 = 0) || d.year % 400 == 00) 
^^^^

我想你的意思是

if ( (d.year % 4 == 0 && d.year % 100 != 0) || d.year % 400 == 00) 
^^^^

00 相当于 0.:)

函数可以写得更简单

bool isLeapYear( struct date d )
{
return ( d.year % 4 == 0 && d.year % 100 != 0 ) || ( d.year % 400 == 0 );
}

关于C2106 : '=' : left operand must be l-value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41727282/

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