0

I'm having a secondary problem as well. I have defined my array, written my functions, and all compiles well, but I'm getting two linking errors that say my hourly temp array is already defined in my test.cpp (main)...uhh, I dunno how to find out how/where to fix it.

0

You can not put array declarations in a header file then include that header file in two or more *.cpp files. If that's what you did then you should declare the array with the extern keyword everywhere except in ONE and only ONE *.cpp file.

// header file
[b]extern[/b] int array[8];

Then in a *.cpp file declare it again without the extern keyword.

Votes + Comments
he knew what I did without even seeing my code
0

that's exactly what I did, thank you....if you don't mind, back on the third page at the bottom I asked a question about calling display functions.

0

I have a function written to display my output, but I've never called a display function before and I'm not sure how to do it. Here is the function

void displaytemp( const int hourlytemps[], int numtemp, double averagetemp)
{
	cout << " Average Temperature: " << averagetemp << endl;
}

how do I call this in main?... I know it's not really necessary to create an output function, it's just practice writing functions and calling stuff from arrays and other functions

Call it just as you would any other function

int main()
{
    int hourlytemps[24];
    int numtemp;
    double averagetemp;

    displaytemp( hourlytemps,numtemp, averagetemp);
}

Your function displaytep() is also incorrect. You can't display an array like that -- have to print each element one at a time, something like this:

displaytemp( const int hourlytemps[], int numtemp, double averagetemp)
{
    for(int i = 0; i < numtemp; i++)
   {
          cout << hourlytemps[i] << "\n";
   }
}
0

Yes, I have a different function for the tabular display, that function is purely for displaying the average of the 24 temps

0

Oops! I see that now. Your function is correct afterall. Please forgive an old man -- blind in one eye and can't see out of the other :)

0

Still problems though, I have a function for high and low temps, low temps always shows 1 and high temp shows 23 unless they are all the same.

int lotemp( int hourlytemps[], int numtemp)
{
	int lowtemp = hourlytemps[0] ;

	for( int i=1 ; i < numtemp ; ++i )
	{
	  if(lowtemp > i)
		 lowtemp = i;
	}
	return (lowtemp);
}

High is the same, just change the sign

0

Okay, hitemps, still comes out to 23, here is the code

int hitemp( int hourlytemps[], int numtemp)
{
	int hitemp = hourlytemps[0] ;

	for( int i=1 ; i < numtemp ; ++i )
	{
	  if(hitemp < hourlytemps[i])
		 hitemp = i;
	}
	return (hitemp);
}

I'll have to read up again to remind myself how to do the line numbers, apologies for that

0

>>I'll have to read up again to remind myself how to do the line numbers, apologies for that
Not a problem -- I just like to see them. Here's how

[code=cplusplus] // your code here

[/code]


line 8 is also wrong in this and the previous post. should be hightemp = hourlytemps[i];

0

hehe, okay, now I feel like an idiot, you'd think I'd never found a min or max before...of course, I haven't with an array..lol..thats going to be hard to get used to. Now have have to learn pointers...weeeeee

Thank you yet again, the entire program actually works now.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.