gpt4 book ai didi

c - 我在 C 程序编码中遇到未知错误

转载 作者:行者123 更新时间:2023-11-30 21:38:05 24 4
gpt4 key购买 nike

这是我的代码:

#include <stdio.h>

main()
{
int yearcounter = 0;
int monthcounter = 0;
int monthcounter2 = 0;
int extramonths = 0;
int monthsalive = 0;
int month;
int day;
int year;
int monthto;
int dayto;
int yearto;
printf("What date were you born? Enter mm/dd/fullyear with no dashes.\n");
scanf(" %d/%d/%d", &month, &day, &year);
printf("What is today's date?\n");
scanf(" %d/%d/%d", &monthto, &dayto, &yearto);

if

(year < 0 && year <= yearto);
year++;
yearcounter++;

if

(month > 0 && month <= 12);
month++;
monthcounter++;

if

(monthto > 0 && monthto <= 12);
{
monthto++;
monthcounter2++;
}
extramonths = monthcounter - monthcounter 2;

if

(extramonths <= 0);
{
yearcounter = yearcounter - 1;
}
monthsalive = yearcounter * 12;

printf("You've been alive %d years.\n", yearcounter);
printf("You've been alive about %d months.\n", monthsalive);
return 0;
}

错误是:

main.c:41:49: error: expected ';' before numeric constant ; extramonths = monthcounter - monthcounter 2;

有人可以帮我吗?

最佳答案

你认为这会做什么?

if

(year < 0 && year <= yearto);
year++;
yearcounter++;

(提示:if 语句末尾有一个分号,并且运算周围没有括号。)

你真正想要的是:

if (year < 0 && year <= yearto)
{
year++;
yearcounter++;
}
<小时/>

在这一行:

extramonths = monthcounter - monthcounter 2;

您的意思是将多月计数器加 2 吗?为此,您需要一个乘法运算符!

extramonths = monthcounter - monthcounter * 2;

或者也许您打算使用变量monthcounter2,在这种情况下,空间就不好

extramonths = monthcounter - monthcounter2;

关于c - 我在 C 程序编码中遇到未知错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20386675/

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