简体   繁体   English

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

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

I am some-what new to Programming in c++ i was assigned a exercise what i'm getting a compile error 我是一些 - 在c ++中编程的新东西我被分配了一个练习,我得到一个编译错误

i was hoping someone can either help me resolve the error or give me some insight as to why its happening Code below /* Exercise 21 Intermediate: Declare a seven-row, two- column int array named temperatures. 我希望有人可以帮助我解决错误,或者给我一些见解,为什么它发生在下面的代码/ *练习21中级:声明一个名为temperature的七行,两列int数组。 The program should prompt the user to enter the highest and lowest temperatures for seven days. 该程序应提示用户输入最高和最低温度七天。 Store the highest temperatures in the first column in the array. 将最高温度存储在阵列的第一列中。 Store the lowest temperatures in the second column. 将最低温度存储在第二列中。 The program should display the average high temperature and the average low temperature. 程序应显示平均高温和平均低温。 Display the average temperatures with one decimal place. 显示小数点后一位的平均温度。 */ * /

#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 cannot convert double' to double ( )[2]' for argument 1' to void calcAverage(double ( )[2])' 44不能将参数1' to double' to转换double' to double( )[2] 1' to void calcAverage(double( )[2])'

void calcAverage(double temperatures[7][2]);

Okay, calcAverage takes a two-dimensional array of doubles. 好的, calcAverage采用二维的双精度数组。

calcAverage(high_average, low_average);

But you passed it two doubles. 但你传了两个双打。

void calcAverage(double temperatures[6][1],double &high_average, double &low_average)

And now it takes a two-dimensional array of doubles and two references. 现在它需要一个二维数组的双精度数和两个参考数。

Pick one of these three and stick to it. 选择这三个中的一个并坚持下去。

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

相关问题 为什么会出现此模板编译错误? - Why am i getting this template compile error? 为什么我会收到错误:当我尝试编译C ++代码时,在Eclipse中初始化&#39;Item :: Item(int)&#39;[-fpermissive]的参数1? - Why am I getting error: initializing argument 1 of 'Item::Item(int)' [-fpermissive] in Eclipse when I try to compile my C++ code? 当我尝试在启用推理引擎的情况下编译OpenCv时,出现错误 - When I try to compile OpenCv with inference engine enabled, I am getting an error 为什么在尝试使用 MSVC 编译 32 位代码时出现错误? - Why am I getting an error when trying to compile 32-bit code with MSVC? 尝试编译XPCOM代码时为什么会出现错误C2440? - Why do I get error C2440 when I try to compile XPCOM code? 为什么我会收到编译错误“ <variable> 没有在此范围内声明”? - Why am I getting compile errors “<variable> not declared in this scope”? 为什么我收到编译错误“使用已删除的函数&#39;std :: unique_ptr ...” - Why am I getting compile error “use of deleted function 'std::unique_ptr …” 当我尝试编译和运行时出现 fstream 错误,“streambuf” - fstream error, "streambuf" when I try to compile and run 当我尝试编译此C ++程序时,它给了我一个错误 - When I try to compile this C++ program, it gives me an error 我尝试编译时使用boost的未定义引用 - undefined reference with boost when I try to compile
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM