What did I do wrong when calling out this function

So here's my code:



#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;

//function prototypes
int readRainFall (ifstream& inFileName, double rainfalls[], int MONTHS);
double getrainTotal(double[], int);
double gethighestRainfall(double rainfalls[], int MONTHS);
double getlowestRainfall(double rainfalls[], int MONTHS);


int main() {


const int MONTHS = 12;

string monthName[MONTHS] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
double rainfallAmount[MONTHS];
int count=0;
double avg;
double totalRain, mostRain, leastRain;
string name, mostMonth, leastMonth, inFileName, outFileName;


cout << "Please enter the name of output file: ";
cin>>outFileName;

//call function
readRainFall (inFile "in6s17.txt", rainfallAmount, MONTHS);//This is where I have problems!!




ofstream outFile;
cin>>outFileName;
outFile.open(outFileName);

outFile << fixed << showpoint << setprecision(1);


outFile << "YEARLY MONTHLY RAINFALL" << endl;
outFile << "Month"<<setw(20)<<"Rainfall in inches"<<endl;


for (int count = 0; count < MONTHS; count++) {
outFile << monthName[count]<<setw(17)<<rainfallAmount[count]<<endl;

}

totalRain = getrainTotal (rainfallAmount, MONTHS);
outFile << "The total rainfall for the year is "<<totalRain<<" inches."<<endl;

avg = totalRain/MONTHS;
outFile << "The average monthly rainfall is "<<avg<<" inches."<<endl;


mostRain = gethighestRainfall(rainfallAmount, MONTHS);
outFile << "The highest rainfall of "<<mostRain<<" occured in April"<<endl;

leastRain = getlowestRainfall (rainfallAmount, MONTHS);
outFile << "The lowest rainfall of "<<leastRain<<" occured in June"<<endl;
outFile << "The lowest rainfall of "<<leastRain<<" occured in July"<<endl;

outFile <<"Rainfall of 4 inches or more occured in February."<<endl;
outFile <<" "<<endl;
outFile<<"Rainfall of 4 inches or more occured in March."<<endl;
outFile << " "<<endl;
outFile << "Rainfall of 4 or more inches occured in April."<<endl;


cout << "Programmer: ";
getline(cin,name);
outFile<<name;
cout << "Processing complete"<<endl;




outFile.close();



return 0;


}


int readRainFall (ifstream& inFile, double rainfalls[], int MONTHS)
{
string inFileName;
int count=0;
cout << "Please enter the name of the input file: ";
cin>>inFileName;
inFile.open(inFileName);
if (!inFile.is_open())
{
cout << "Error opening file"<<endl;
}
else {
while(count<MONTHS && inFile >> rainfalls[count])
count++;
}
inFile.close();
return 0;


}


double getrainTotal (double rainfalls[], int MONTHS)

{
double total=0;
for ( int count = 0; count < MONTHS; count++)
total += rainfalls[count];
return total;
}

double gethighestRainfall(double rainfalls[], int MONTHS)
{
double highest;
highest = rainfalls[0];
for (int count=1; count <MONTHS; count++)
{
if (rainfalls[count] > highest)
highest = rainfalls[count];
}
return highest;

}

double getlowestRainfall(double rainfalls[], int MONTHS)

{
double lowest;
lowest = rainfalls[0];
for (int count =1; count <MONTHS; count++)
{
if (rainfalls[count]< lowest)
lowest = rainfalls[count];

}
return lowest;

}




It keeps saying stuff like "Expeceted ')' " or something else. I don't know what I'm doing wrong?

readRainFall (inFile "in6s17.txt", rainfallAmount, MONTHS);
> It keeps saying stuff like "Expeceted ')' " or something else
copy-paste the error message verbatim.
If you don't understand the message, don't paraphrase it.
You need to create and open an std::ifstream object and pass that th your readRainFall() function.
1
2
3
4
 ...
ifstream inFile("in6s17.txt");
readRainFall (inFile , rainfallAmount, MONTHS);
 ...

Last edited on
@ne55t "Expeceted ')' " is exactly what it said

@nuderobmonkey

That works, but would that count as hardcoding? (I'm not supposed to hardcode.)
This was just an example. Feel free changing the 'hardcoded' string with the string variable of your choice ;-)
Does this count as not coding?

ifstream inFile(inFileName);
readRainFall (inFile, rainfallAmount, MONTHS);
Topic archived. No new replies allowed.