所以我正在编写这个简单的程序来使用此处找到的高斯算法计算任何日期的日期。
#include <iostream>
using namespace std;
//Using the Gaussian algorithm
int dayofweek(int date, int month, int year ){
int d=date;
if (month==1||month==2)
{int y=((year-1)%100);int c=(year-1)/100;}
else
{int y=year%100;int c=year/100;}
int m=(month+9)%12+1;
int product=(d+(2.6*m-0.2)+y+y/4+c/4-2*c);
return product%7;
}
int main(){
cout<<dayofweek(19,1,2054);
return 0;
}
这是一个非常简单的程序,更令人费解的是输出。
:In function dayofweek(int, int, int)’:
:19: warning: unused variable ‘y’
:19: warning: unused variable ‘c’
:21: warning: unused variable ‘y’
:21: warning: unused variable ‘c’
:23: error: ‘y’ was not declared in this scope
:25: error: ‘c’ was not declared in this scope
它说我的变量未使用,但又说它没有声明?谁能告诉我怎么了。