2013-04-23 3 views
-5

누군가이 오류의 원인을 파악하는 데 도움이 될 수 있다면 매우 행복 할 것입니다. 내 코드를 컴파일 해야하는 것 같아요 아직 내 void 함수를 모두이 오류가 발생합니다. 여기 오류 LNK2019 - 내 코드가 컴파일해야하지만이 오류가 발생합니다.

내 코드가

은 ...

#include<iostream> 
#include<iomanip> 
#include<fstream> 


using namespace std; 

// global constant variables 
const int YEARS = 8; 
const int MONTHS = 12; 
const int SPACER =5; 

// function prototypes 

// function to read in values 
void getData(double[][MONTHS], int[]); 
// function to display values in table format 
void printData(double[][MONTHS], int[]); 


// function to print data to screen in table format using arrays 

int main() 
{ 
    double rain [YEARS][MONTHS]; 
    int years[YEARS]; 

    getData(rain, years); 
    printData(rain, years); 

return 0; 
} 


// function definitions 

void getData (double rainArray[][YEARS], int yearArray[]) 
{ 
    ifstream fin; 

    fin.open("rainfall.txt"); 

    if (!fin) 
    { 
     cout << "Error opening file, shutting down now.\n" ; 
     exit(EXIT_FAILURE); 
    } 
    else 
    { 
     for(int i = 0; i < YEARS; i++) 
     { 
      fin >> yearArray[i]; 
      for (int j = 0; j < MONTHS; j++) 
      { 
       fin >> rainArray[i][j]; 
      } 
     } 
    } 
    fin.close(); 
} 

void printData (double rainArray[][YEARS], int yearArray[]) 
{ 

    for (int i = 0; i < YEARS; i++){ 
     cout << yearArray[i] << setw(SPACER); 
     for (int j = 0; j < MONTHS; j ++) 
      cout << rainArray[i][j] << setw(SPACER); 
    } 
    cout << endl; 
} 
+0

정확하게 오류 메시지가 무엇입니까? * 실제 * 오류 메시지와 해당 오류를 일으킨 행 (해당되는 경우)을 포함시켜주십시오. –

+0

그 오류의 의미를 찾았습니까? –

+0

해당 기능은 어디에 구현 되었습니까? –

답변

1

당신은 당신의 genData 매개 변수와 rain 배열의 차원 불일치가 있습니다 들 :

double rain [YEARS][MONTHS]; 

을하지만 잘못된 방법으로 그것을 사용 :

void getData (double rainArray[][YEARS], int yearArray[]) 
        //^^^ should be rainArray[YEARS][MONTHS] 

과 유사한 문제function