Hello, I need help printing my results to an output file with the program that I have below. I am getting an error "too few arguements to function". It has been a couple of years since I did C++ using .txt, so any help is appreciated. Thank you.
Goals:
- Display the high and low temperatures for each month
- Display highest temperature average out of all months
- Display lowest temperature average out of all months
- Display highest temperature out of all months
-Display lowest temperature out of all months.
My input.txt file: 50 33 45 25 55 32 60 50 75 60 80 74 92 75 98 78 85 60 70 53 50 35 53 20
Example of output I wish to create:
Jan 60 23
Feb 55 20
.
.
Dec 60 25
The average high temperature is 57.50
The average low temperature is 21.50
The highest temperature is 60
The lowest temperature is 20
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
void getdata(ifstream& inData,ofstream& outData);
double averagehigh(int temperature[][2],double average_highs,ifstream& inData,int lowest_temp,int highest_temp);
double averagelow(int temperature[][2],double average_lows,ifstream& inData,int lowest_temp,int highest_temp);
int indexHighTemp(int temperature[][2],int highest_temp,int lowest_temp,ifstream& inData);
int indexLowTemp(int temperature[][2],int lowest_temp,int highest_temp,ifstream& inData);
int main()
{
int Temp[12][2] = {{50,33},{45,25},{55,32},{60,50},{75,60},{80,74},{92,75},{98,78},{85,60},{70,53},{50,35},{53,20}};
string month[12][12] = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sept","Oct","Nov","Dec"};
int temp_highs;
int temp_lows;
int highest;
int lowest;
double average_high;
double average_low;
ifstream inData;
ofstream outData;
while (inData>>temp_highs>>temp_lows)
{
outData<<month<<" "<<temp_highs<<temp_lows<<endl;
}
outData<<"The average high temperature is "<<averagehigh(Temp,average_high,inData)<<endl;
outData<<"The average low temperature is "<<averagelow(Temp,average_low,inData)<<endl;
outData<<"The highest temperature is "<<indexHighTemp(Temp,temp_highs,inData)<<endl;
outData<<"The lowest temperature is "<<indexLowTemp(Temp,temp_lows,inData)<<endl;
inData.close();
outData.close();
system ("PAUSE");
return 0;
}
void getdata(ifstream& inData,ofstream& outData)
{
inData.open ("input.txt"); // file the contains the numbers
outData.open ("input_output.txt"); // file that contain the results
}
double averagehigh(int temperature[][2], double average_highs,ifstream& inData,ofstream& outData,int lowest_temp,int highest_temp)
{
int sum = 0;
while (inData>>highest_temp>>lowest_temp)
{
for (int i=0; i<2; i++)
{
for (int j=0; j<12; j++)
{
sum+=highest_temp;
average_highs = ( sum / 12 );
}
}
}
return average_highs;
}
double averagelow(int temperature[][2], double average_lows,ifstream& inData,ofstream& outData,int lowest_temp,int highest_temp)
{
int sum = 0;
while (inData>>highest_temp>>lowest_temp)
{
for (int i=0; i<2; i++)
{
for (int j=0; j<12; j++)
{
sum+=lowest_temp;
average_lows = ( sum / 12 );
}
}
}
return average_lows;
}
int indexHighTemp(int temperature[][2], int highest_temp, int lowest_temp,ifstream& inData,ofstream& outData)
{
while (inData>>highest_temp>>lowest_temp)
{
for (int i=0; i<2; i++)
{
for (int j=0; j<12; j++)
{
if(temperature[i][j] > highest_temp)
highest_temp = temperature[i][j];
}
}
}
return highest_temp;
}
int indexLowTemp(int temperature[][2], int lowest_temp, int highest_temp,ifstream& inData,ofstream& outData)
{
while (inData>>highest_temp>>lowest_temp)
{
for (int i=0; i<12; i++)
{
for (int j=0; j<2; j++)
{
if(temperature[i][j] < lowest_temp)
lowest_temp = temperature[i][j];
}
}
}
return lowest_temp;
}