Receving Errors When Compiling Code

This what what I'm getting as errors.
tempDriver.cpp: In function ‘int main()’:
tempDriver.cpp:20: error: expected initializer before ‘int’
tempDriver.cpp:21: error: ‘temperatures’ was not declared in this scope
tempDriver.cpp:21: error: ‘numDays’ was not declared in this scope
tempFns.h:30: error: too few arguments to function ‘void tempAvg(double (*)[5], int, int)’

The most confusing error is the last one. I'm not sure what it means. And for 21 I just have to declare temperatures and numDays as zero before I write it?
And I have never received that type of a error message before.

This my my tempDriver.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
#include <fstream>

#include "tempFns.h"

using namespace std;


int main (void)
{
	
	double temperatures [MaxDays][MaxTimes]
	//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;
		
	//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;
	
}


This is my tempFns.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <iostream>
#include <fstream>
#include <iomanip>


using namespace std;

const int MaxDays = 31;  // Maximum number of days in a month
const int MaxTimes = 5; // Maximum number of times temperature is measured in 



//-----------------------------------------------------------------------------------------
//
//  Function: tempAvg ()
//
//	Parameters:	
//    input tempArray: double; array of temperatures
//    input days: integer; number of days for that month
//    input times: integer; number of times temperature is measured each day 
//                    for that month
//    
//	Pre-condition: input array must be populated with valid temperatures;
//                 input number of days must be between 28 and MaxDays (inclusive)
//                 input number of times must be at least one less than MaxTimes
//  Post-condition: The average temperature for each day is calculated and 
//                  stored in the last column of the array 
//-----------------------------------------------------------------------------------------

void tempAvg (double [] [MaxTimes], int days, int times);

// DO: Put the prototype for the function tmpAvg () here
//     2 points







//-----------------------------------------------------------------------------------------
//
//  Function: inputFmFile ()
//
//	Parameters:	
//    input tempArray: double; array of temperatures
//    output days: integer; number of days for that month
//    output times: integer; number of times temperature is measured each day 
//                    for that month
//    
//	Post-condition: The temperatures for the month are read in from a 
//                  user-specified file and stored in the array; 
//                  The number of days in the month and number of times 
//                  the temperature is measured are returned to calling function.
//-----------------------------------------------------------------------------------------

void inputFmFile (double [][MaxTimes], int &, int &);


//-----------------------------------------------------------------------------------------
//
//  Function: inputFmFile ()
//
//	Parameters:	
//    input tempArray: double; array of temperatures
//    input days: integer; number of days for that month
//    input times: integer; number of times temperature is measured each day 
//                    for that month
//    
//	Pre-condition: input array must be populated with valid temperatures;
//	Post-condition: The temperatures for the month are displayed
//                  on the screen
//-----------------------------------------------------------------------------------------

void outputData (double [][MaxTimes], int, int);
Any help.???
You are missing a ';' after double temperature[blah][blah]. This is also causing the other errors in the first file.

In the second file, leave the brackets empty. I think that this may be the problem.
hi,
ERROR 30:
on line 33 function--> tempAvg (); takes no arguments.
it should take array and 2 integers wright??

and where have you defined this:
inputFmFile (temperatures, numDays, numTimes);

there is no definition for this one too:
void outputData (double [][MaxTimes], int, int);
no def for tempAvg as well.
ERROR 21:
make variables global and extern if u use them out of scope

ERROR 20:
did u forget semicolon :) on line 12!

where is definition I gave u yesterday.
this code will never compile man.


I'm using three codes. This is the other one. Also, I know this is very complicated that's why I'm having so much trouble. I need yo use all three to run one program.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <iostream>
#include <fstream>


#include "tempFns.h"

using namespace std;


void tempAvg (double tempArray [maxDays] [maxTimes], int , int);
{
	if (days > maxDays || days < 28 || times >= maxTimes) exit (1);
	double sum = 0; 
	for (i = 0; i < days; i++) {
		for (j = 0; j < times; j++) 
		{
			sum += tempArray [i] [j];
		}
		tempArray [i] [maxTimes] = sum / times; 
		sum = 0;
	}
}

// DO: Write the complete definition of the function tempAvg () below









void inputFmFile (double tempArray [][MaxTimes], int &days, int &times)
{
	bool worked = true;
	string inFileName;
	ifstream inStr;
	
	do 
	{
		cout << "Enter name of file to read from: ";
		cin >> inFileName;
		
		inStr.open (inFileName.c_str());
		if (inStr.fail())
		{
			cerr << "Error opening file. Try again." << endl;
			inStr.clear();
			worked = false;
		}
		else 
			worked = true;
		
	} while (!worked);
	
	inStr >> days >> times;
	
	// Use a for loop to enter data into the array
	
	for (int i=0; i < days; i++)
		for (int j=0; j < times; j++)
			inStr >> tempArray [i][j];
	
	// Initialize daily averages to 0 - set the last column to 0 
	for (int i=0; i < days; i++)
		tempArray [i][times] = 0.0;

}



void outputData (double tempArray [][MaxTimes], int days, int times)
{
	cout << endl << "The temperatures for the month are : " << endl;
	cout.setf(ios::fixed);
	cout.precision (2);
	// Use a for loop to display the temperatures
	
	cout << setw(9) << "Day";
	for (int i=0; i < times-1; i++)
		cout << setw(8) << "Temp" << i+1;
	cout << setw(8) << "Average" << endl;
	
	for (int i=0; i < days; i++)
	{
		cout << setw(9) << i+1;
		for (int j=0; j < times; j++)
			cout << setw(9) << tempArray [i][j];
		cout << endl;
	}
	
}
any help??
I know someone will say that isn't good solving someones homework but this time it's hard to just comment those 3 files.....
so here is the code sort in files (no comments cos I remove them while paste int my compiler):

tempFns.h
1
2
3
4
5
6
7
8
9
10
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;

const int MaxDays = 31;
const int MaxTimes = 5;
void tempAvg (double [] [MaxTimes], int, int);
void inputFmFile (double [][MaxTimes], int&, int&);
void outputData (double [][MaxTimes], int, int);


tempDriver.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include "tempFns.h"

int main () {
	
	double temperatures [MaxDays][MaxTimes];
	int numDays = 0;
	int numTimes = 0;
	inputFmFile (temperatures, numDays, numTimes);

	cout << "Temperature data before calculating averages." << endl;
	outputData (temperatures, numDays, numTimes);
	cout << endl;
	
	tempAvg (temperatures, numDays, numTimes);

	cout << "Temperature data after calculating averages." << endl;
	outputData (temperatures, numDays, numTimes+1);
	cout << endl;
		
	cout << "Bye!" << endl;
	return 0;
}


Definitions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "tempFns.h"

void tempAvg (double tempArray [MaxDays] [MaxTimes], int days, int times) {
	if (days > MaxDays || days < 28 || times >= MaxTimes) exit (1);
	double sum = 0; 
	for (short i = 0; i < days; i++) {
		for (short j = 0; j < times; j++) {
			sum += tempArray [i] [j];
		}
		tempArray [i] [MaxTimes] = sum / times; 
		sum = 0;
	}
}

void inputFmFile (double tempArray [][MaxTimes], int &days, int &times)
{
	bool worked = true;
	string inFileName;
	char* name = "";
	ifstream inStr;
	
	do {
		cout << "Enter name of file to read from: ";
		cin >> name;
		inFileName = name;
		
		inStr.open (inFileName.c_str());
		if (inStr.fail())
		{
			cerr << "Error opening file. Try again." << endl;
			inStr.clear();
			worked = false;
		}
		else 
			worked = true;
		
	} while (!worked);
	
	inStr >> days >> times;
	
	for (int i=0; i < days; i++)
		for (int j=0; j < times; j++)
			inStr >> tempArray [i][j];

	for (int i=0; i < days; i++)
		tempArray [i][times] = 0.0;
}

void outputData (double tempArray [][MaxTimes], int days, int times)
{
	cout << endl << "The temperatures for the month are : " << endl;
	cout.setf(ios::fixed);
	cout.precision (2);
	
	cout << setw(9) << "Day";
	for (int i=0; i < times-1; i++)
		cout << setw(8) << "Temp" << i+1;
	cout << setw(8) << "Average" << endl;
	
	for (int i=0; i < days; i++) {
		cout << setw(9) << i+1;
		for (int j=0; j < times; j++)
			cout << setw(9) << tempArray [i][j];
		cout << endl;
	}
}
how would I compile this? Would I just need to compile the Driver file or what?
yes tempDriver.cpp
place definitions into another cpp.
I didn't test run prgram just fixing some major errors.
Yeah I thought that was what I needed to do and I tried to compile it and I'm receiving some weird message in my compiler that I have never seen before.

Any ideas on what I need to correct?
Last edited on
This looks like a linker error, maybe. Try adding all the cpp files to a project and compiling all of them. If that doesn't work, I have no idea.
Yeah I'm not sure. I might have to make a makefile.
Topic archived. No new replies allowed.