This is what I have, How would I declare the array based on what I already have?

#include <iostream>
#include <fstream>

#include "tempFns.h"

using namespace std;


int main (void)
{
// DO: declare an array of type double called temperatures 
// Use the constant MaxDays for the number of rows
// and the constant MaxTimes for the number of columns	


}

int numDays = 0; // holds number of days in the month 
int numTimes = 0; // holds number of times the temperature is measured each day

// Read the data from a file
inputFmFile (temperatures, numDays, numTimes);

// Display the data on the screen
cout << "Temperature data before calculating averages." << endl;
outputData (temperatures, numDays, numTimes);
cout << endl;

// DO: Call the function tempAvg () here 
tempAvg ();



// Display the data on the screen
cout << "Temperature data after calculating averages." << endl;
outputData (temperatures, numDays, numTimes+1);
cout << endl;

cout << "Bye!" << endl;
return 0;

}

double temperatures[MaxDays][MaxTimes]; , perhaps? Is this a trick question, or do you not own a book on C++?

double temperatures[MaxDays][MaxTimes]; , perhaps? Is this a trick question, or do you not own a book on C++?

I had to lend my book to a friend so I'm stuck without one now.

Also did a call the variable right later in the program?

Just want to make sure.

THanks

>> Also did a call the variable right later in the program?

You don't call a variable. You call a function using a variable as a parameter. Without seeing the function, it's hard to tell whether you called it right.

#include <iostream>
using namespace std;

int main()
{
	int cols, rows;
	cout << "How many rows do you need in your matrix? ";
	cin >> rows;
	cout << "And ... How many columns? ";
	cin >> cols;

	int **myMatrix;

	myMatrix = new int*[rows];
	
	for (int i=0; i<rows; i++)
	
	myMatrix[i] = new int[cols];

	cout << "Now fill up your " << rows << "x" << cols << " matrix:\n";
	for (i=0; i< rows; i++)
		for (int j=0; j<cols; j++)
			cin >> myMatrix[i][j];
	//...............................................................//

	//............................Output.............................//
	cout << "\nYou entered the following matrix\n";
	for (i=0; i<rows; i++)
	{
		for (int j=0; j<cols; j++)
			cout << myMatrix[i][j] << " ";
		cout << endl;
	}
	//...............................................................//
	
	//.................memory deallocation..............//
	for (i=0; i<rows; i++)
		delete [] myMatrix[i];
	delete [] myMatrix;
	//..................................................//
	return 0;
}

Edited 5 Years Ago by Narue: Added code tags

This article has been dead for over six months. Start a new discussion instead.