错误编译简单程序错误LNK2019

时间:2015-04-29 03:12:03

标签: c++

错误1错误LNK2019:未解析的外部符号“int __cdecl findlowest(int,int,int,int,int)”(?findlowest @@ YAHHHHHH @ Z)在函数_main G中引用:\ C ++ \ Chapter 6 \最低分数drop \最低分数下降\ Source.obj最低分数下降

#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;
}

2 个答案:

答案 0 :(得分:1)

当您编写函数 public static void main(String args[]) throws ParseException, IOException { /* Initialization */ HashMap<String, String[]> synonymMap = new HashMap<String, String[]>(); synonymMap = populateSynonymMap(); // populate the map Scanner scanner = new Scanner(System.in); String input = null; /*End Initialization*/ System.out.println("Welcome To DataBase "); System.out.println("What would you like to know?"); System.out.print("> "); input = scanner.nextLine().toLowerCase(); String[] inputs = input.split(" "); for (String ing : inputs) { // iterate over each word of the sentence. boolean found = false; for (Map.Entry<String, String[]> entry : synonymMap.entrySet()) { String key = entry.getKey(); String[] value = entry.getValue(); if (key.equals(ing) || Arrays.asList(value).contains(ing)) { found = true; parseFile(entry.getKey());`` } break; } if (found) { break; } } } 的定义时,您会出现打字错误。

findlowest

int findLowest(int score1, int score2, int score3, int score4, int score5) 中的l是大写的,其中前向声明和函数调用的小写findLowest

l

答案 1 :(得分:0)

正如阿比吉特正确指出的那样,这是由一个错字造成的。为了进一步说明,您已经声明了一个名为findlowest的函数,该函数需要5 int:它的签名恰当int findlowest(int, int, int, int, int)。然后,您尝试在main中调用该函数。这是正确编译的,因为编译器知道该函数的声明及其所需的全部内容;但是,当您的程序尝试链接时,它需要函数int findlowest(int, int, int, int, int)的定义(因为您正在调用它),但它找不到定义,这是链接器错误所说的。 int findLowest是未使用的函数的新声明和定义。