【发布时间】:2013-12-21 14:34:10
【问题描述】:
这是我的代码:
#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: 错误:预期 ';'在数字常量之前 ; extramonths = 月计数器 - 月计数器 2;
有人可以帮帮我吗?
【问题讨论】:
-
这些
if语句看起来像您在教科书中看到的吗? -
编译器正在告诉你错误所在的文件、行和列!
monthcounter和 2 之间缺少某些内容。 -
这个错误对我来说似乎很有描述性,不知道你为什么说它是“未知的”
-
那么,
extramonths = monthcounter - monthcounter 2;应该是什么意思?它对我们和编译器一样毫无意义。当无法弄清楚您要做什么时,您如何期望人们“帮助您”? -
这是我见过的最丑陋的代码之一。更不用说“bugginess”了。
标签: c error-handling