我是一些 - 在c ++中编程的新东西我被分配了一个练习,我得到一个编译错误
我希望有人可以帮助我解决错误,或者让我了解其发生的原因 代码如下 / * 练习21中级:声明一个名为temperature的七行两列int数组。 该程序应提示用户输入最高和最低温度七天。 将最高温度存储在阵列的第一列中。 将最低温度存储在第二列中。 程序应显示平均高温和平均低温。 显示小数点后一位的平均温度。 * /
#include <iostream>
#include <iomanip>
using namespace std;
//function prototype
void calcAverage(double temperatures[7][2]);
main()
{
double temperatures[7][2] = {0};
float high = 0.0;
float low = 0.0;
double high_average = 0.0;
double low_average = 0.0;
cout << "Please enter the high then low for the last 7 days " <<endl;
for(int x = 0; x < 6; x += 1)
{
cout << "Please enter the High for day: "<< x+1<<": ";
cin >> high;
temperatures[0][x] = high;
}
for(int x = 0; x < 6; x += 1)
{
cout << "Please enter the Low for day: "<< x+1<<": ";
cin >> low;
temperatures[1][x] = high;
}
//Error is here
calcAverage(high_average, low_average);
// end error
system("pause");
}
void calcAverage(double temperatures[6][1],double &high_average, double &low_average)
{
float accumulator = 0.0;
//for hot average
for(int x = 0; x < 6; x += 1)
{
accumulator += temperatures[0][x];
}
high_average = accumulator;
// for cold average
accumulator = 0.0;
for(int x = 0; x < 6; x += 1)
{
accumulator += temperatures[1][x];
}
low_average = accumulator;
}
44无法转换double' to
double()[2]'参数1' to
void calcAverage(double()[2])'
答案 0 :(得分:2)
void calcAverage(double temperatures[7][2]);
好的,calcAverage
采用二维数组双倍。
calcAverage(high_average, low_average);
但是你通过了两次双打。
void calcAverage(double temperatures[6][1],double &high_average, double &low_average)
现在它需要一个二维的双精度数组和两个参考数据。
选择其中一个并坚持下去。