我比c更精通c#而且我正在尝试写一个程序来计算好星期五。
感谢所有帮助它现在工作对不起大多数是我应该知道的愚蠢的东西。
int main(void)
{
/*variables I will be using*/
int year;
int a;
int b;
int c;
int d;
int e;
int f;
/*what will the computer print first*/
printf("Welcome to the Good Friday Computing Program!\n Please enter\n a year between 1982 and 2048: ");
scanf("%d", &year);
/*determine if yeat is with in 1982 and 2048*/
if ( year >= 1982)
{
if (year >= 2048)
{
printf("Enter year from 1982 to 2048");
}
else
{
/*computing good friday*/
a = year % 19;
b = year % 4;
c = year % 7;
d = (19 * a + 24) % 30;
e = (2 * b + 4 * c + 6 * d + 5) % 7;
f = d + e;
/* determine if march or april */
if (f > 11)
{
printf("Good Friday in %d is April %d", year, f - 11);
}
else
{
printf("Good Friday in %d is March %d", year, f + 20);
}
}
}
else
{
printf("Enter year from 1982 to 2048");
}
/*keeps window open*/
getchar();
getchar();
return 0;
}
答案 0 :(得分:1)
变化
scanf("%y", &year);
到
scanf("%d", &year);
%d
表示整数
您仍然会收到错误,因为您需要更改另外2个地方
if (f > 11)
{
printf("Good Friday in %d is April %d", year, f + 20);
}
else
{
printf("Good Friday in %d is March %d", year, f + 20);
}
答案 1 :(得分:0)
您遇到了以下问题:
scanf("%y")
应为scanf("%d")
printf("%y")
应为printf("%d")
如上所述 - &
为*
。
那是一个轰炸机。
答案 2 :(得分:-1)
关于保持窗口打开
getchar();
getchar();
导致它保持开放