每次我尝试运行下面的代码时,它都会显示两个错误。这两个错误都是第 43 行和第 56 行中未定义“标识符”数组。
什么可能导致此问题,我该如何解决?
#include <iostream>
using namespace std;
typedef double* arrayT;
double avg(arrayT data, int length);
double min(arrayT data, int length);
double max(arrayT data, int length);
int main()
{
cout << "Please input the number of temperatures to be read." << endl;
int num;
cin >> num;
arrayT temperatures = new double[num];
for(int i = 0; i < num; i++)
{
cout << "Input temperature " << (i+1) << ":" << endl;
cin >> temperatures[i];
}
cout << "The average temperature is " << avg(temperatures, num) << endl;
cout << "The highest temperature is " << max(temperatures, num) << endl;
cout << "The lowest temperature is " << min(temperatures, num) << endl;
}
double avg(arrayT data, int length)
{
double sum = 0.0;
for(int i = 0; i < length; i++)
sum += data[i];
return sum/length;
}
double min(arrayT data, int length)
{
if(length == 0)
return 0;
double min = array[0];
for(int i = 1; i < length; i++)
if(array[i] < min)
min = array[i];
return min;
}
double max(arrayT data, int length)
{
if(length == 0)
return 0;
double max = array[0];
for(int i = 1; i < length; i++)
if(array[i] > min)
max = array[i];
return max;
}