繁体   English   中英

为什么我在尝试编译时遇到此编译错误?

[英]Why am i getting this compile error when i try to compile?

我是一些 - 在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不能将参数1' to double' to转换double' to double( )[2] 1' to void calcAverage(double( )[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)

现在它需要一个二维数组的双精度数和两个参考数。

选择这三个中的一个并坚持下去。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM