2015-04-29 49 views
-1

錯誤1錯誤LNK2019:無法解析的外部符號「int __cdecl findlowest(int,int,int,int,int)」(?findlowest @@ YAHHHHHH @ Z)在函數_main中引用G:\ C++ \第6章\最低得分下降\最低得分下降\ Source.obj最低得分下降錯誤編譯簡單程序錯誤LNK2019

#include <iostream> 
#include <iomanip> 
using namespace std; 

//Function prototypes 
void getscore(int &score); 
int findlowest(int, int, int, int, int); 
void calcAverage(int, int, int, int, int, int); 

int lowest = 0; 

int main() 
{ 
int score1, score2, score3, score4, score5; 

getscore(score1); // return 1st score 
getscore(score2); // return 2nd score 
getscore(score3); // return 3rd score 
getscore(score4); //return 4th score 
getscore(score5); //return 5th score 


lowest = findlowest(score1, score2, score3, score4, score5); 

calcAverage(score1, score2, score3, score4, score5, lowest); 

return 0; 
} 

void getscore(int &score) 
{ 
for (int count = 1; count <= 5; count++) 
{ 
    cout << "Please enter test score for test " << count << ": "; 
    cin >> score; 
} 
} 

int findLowest(int score1, int score2, int score3, int score4, int score5) 
{ 
int calclowest = score1; 
{ 
    if (score2 < score1) 
     calclowest = score2; 
    else if (score3 < score2) 
     calclowest = score3; 
    else if (score4 < score3) 
     calclowest = score4; 
    else if (score5 < score4) 
     calclowest = score5; 
} 
cout << "The lowest test score is " << calclowest << endl; 
return calclowest; 
} 

void calcAverage(int score1, int score2, int score3, int score4, int score5, int lowest) 
{ 
int average; 
average = ((score1 + score2 + score3 + score4 + score5) - lowest)/4; 
cout << "The average of the 4 highest scores is " << average << endl; 
} 

回答

1

當你寫的功能findlowest的定義,你有一個拼寫錯誤。

int findLowest(int score1, int score2, int score3, int score4, int score5) 

findLowestl是在如向前聲明和函數調用具有小寫l大寫。

int findlowest(int, int, int, int, int); 
lowest = findlowest(score1, score2, score3, score4, score5); 
+0

這樣一個簡單的錯誤,但似乎導致我這麼多問題。感謝您的幫助。總是有助於獲得第二雙眼睛的東西。 – skididdy

0

正如Abhijit正確指出的,這是由錯字造成的。爲了進一步闡述,你已經聲明瞭一個叫做findlowest的函數,它需要5 int:它的簽名恰好是int findlowest(int, int, int, int, int)。然後,您嘗試在main中調用該功能。這樣編譯正確,因爲編譯器知道該函數的聲明,這就是它所需要的;但是,當程序嘗試鏈接它時,需要定義函數int findlowest(int, int, int, int, int)(因爲您正在調用它),但它無法找到定義,這是鏈接器錯誤的說法。 int findLowest是一個未使用的函數的新聲明和定義。