简体   繁体   中英

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

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. 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])'

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

Okay, calcAverage takes a two-dimensional array of doubles.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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