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.
#include <iostream>
#include <fstream>
#include "tempFns.h"
usingnamespace 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;
}
#include <iostream>
#include <fstream>
#include <iomanip>
usingnamespace std;
constint MaxDays = 31; // Maximum number of days in a month
constint 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);
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.
#include <iostream>
#include <fstream>
#include "tempFns.h"
usingnamespace 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 ×)
{
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;
}
}
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):
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.