[英]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.