【发布时间】:2015-10-06 16:48:42
【问题描述】:
我收到多条涉及
的消息LNK2019:未解析的外部符号“int_cdecl findLowest(int,int)”
在 function_main 中引用。每当我尝试编译我的程序时,这些消息中的 4 条都会弹出 op。我不知道如何解决这个问题,否则我不会寻求帮助。
#include <iostream>
using namespace std;
// This program calculates the average of the inputed temperatures and finds the highest and lowest
//
int main()
{
int numOfTemp;
int temp[50];
int pos;
double findAverage(int, int);
int findLowest(int, int);
int findHighest(int, int);
cout << "Please input the number of temperatures to be read (no more than 50)" << endl;
cin >> numOfTemp;
for (pos = 1; pos <= numOfTemp; pos++)
{
cout << "Input temperature " << pos << ":" << endl;
cin >> temp[pos];
}
cout << "The average temperature is " << findAverage(temp[pos], numOfTemp) << endl;
cout << "The lowest temperature is " << findLowest(temp[pos], numOfTemp) << endl;
cout << "The highest temperature is " << findHighest(temp[pos], numOfTemp) << endl;//calls function
}
double findAverage(int table[], int num)
{
for (int i = 0; i < num; i++)
{
int sum = 0;
sum += table[i];
return (sum / num); // calculates the average
}
}
int findLowest(int table[], int num)
{
float lowest;
lowest = table[0]; // make first element the lowest price
for (int count = 0; count < num; count++)
if (lowest > table[count])
lowest = table[count];
return lowest;
}
// This function returns the highest price in the array
int findHighest(int table[], int num)
{
float highest;
highest = table[0]; // make first element the highest price
for (int count = 0; count < num; count++)
if (highest < table[count])
highest = table[count];
return highest;
}
【问题讨论】:
-
如果您想获得帮助,请发布确切的错误消息
-
您是否尝试在
main()之外声明您的函数? -
@demonplus 我在里面编辑了消息
-
“为什么...”并不完全是重复的,但我认为该问题的标题包含您问题的答案。
标签: c++ arrays function input output