Question
I am having difficulties with this code. How do I get the code to cout { Highest temperature recorded in the month of: June Lowest
I am having difficulties with this code. How do I get the code to cout
{
Highest temperature recorded in the month of: June
Lowest temperature recorded in the month of: February
}
Also, how do I get the output
"The average high of all the temperatures" and "The average low of all the temperatures" in decimal form. Right now the output is correct, but it is just missing the decimal part.
#include
#include
#include
#include
#include
const int rows = 12; //to make the rows constant
const int columns = 2; //to make the columns constant
using namespace std;
void getData (int listTemp[rows][columns], ifstream& infile); //reads and stores data into the two dimensional array
void averageHigh ( int listTemp[rows][columns]); //calculates and returns the average high temperature for the year
void averageLow (int listTemp[rows][columns]); //calculates and returns the average low temperature for the year
void indexHighTemp (int listTemp[rows][columns], ofstream& outfile);//returns the index of the highest high temperature in the array
void indexLowTemp (int listTemp[columns][columns], ofstream& outfile); //returns the index of the lowest low temperature in the array
ifstream infile;
ofstream outfile;
int main()
{
int listTemp[rows][columns]; //2-D array
string inputFileName;
string outputFileName;
cout
"or file must be in current workspace folder to avoid inputting the full path: ";
getline(cin, inputFileName);
infile.open(inputFileName.c_str()); //open infile
if(!infile) // checking whether the input file exist or not
{
cout
return -1;
}
cout
getline(cin, outputFileName);
outfile.open(outputFileName.c_str());
//set showpoint so result will be able to show decimal points
outfile
//calls functions
getData(listTemp, infile);
averageHigh(listTemp);
averageLow(listTemp);
indexHighTemp(listTemp, outfile);
indexLowTemp(listTemp, outfile);
infile.close();
outfile.close();
return 0;
}
void getData(int listTemp[rows][columns], ifstream& infile)
{
int x;
int y;
for (x=0; x
{
for( y=0; y
{
infile >> listTemp[x][y]>>ws;
}
}
}
void averageHigh ( int listTemp[rows][columns])
{
int x=1;
int sum = 0;
double avg; //average of the highs
for (x=0; x
{
sum = listTemp[x][0] + sum;
}
avg = sum/x;
outfile
}
void averageLow ( int listTemp[rows][columns])
{
int sum = 0;
double avg; //average of the lows
for (int x=0; x
{
sum = listTemp [x][1] + sum;
}
avg = sum/12;
outfile
}
void indexHighTemp ( int listTemp[rows][columns], ofstream& outfile) //find highest in the high column
{
int highestIndex = 0;
for(int x = 0; x
{
if(listTemp[0][x] > highestIndex)
highestIndex = listTemp[0][x];
}
outfile
}
void indexLowTemp ( int listTemp[rows][columns], ofstream& outfile) //find the lowest in the low column
{
int lowestIndex = 0;
for(int x = 0; x
{
if(lowestIndex > listTemp[0][x])
lowestIndex = listTemp[0][x];
}
outfile
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started