簡體   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