Hi fellow c++ programmers,
I need some help with an assignment from my c++ class. The assignment is to use a input file with the following
1 4/12/2007 34 -- 1 is the reference number, date , and temperature to be converted to farenheit.
Now i have to output it to a .txt file that looks like this:
CELCIUS TO FAHRENHEIT CONVERSION
----------------------------------
REF. DATE CONVERSION
1 4/12/2007 1°F
2 4/12/2007 1°F
3 4/12/2007 2°F
4 4/12/2007 3°F
6 4/12/2007 4°F
7 4/12/2007 5°F
8 4/12/2007 6°F
9 4/12/2007 6°F
10 4/12/2007 7°F
11 4/12/2007 7°F
12 4/12/2007 8°F
13 4/12/2007 9°F
14 4/12/2007 10°F
15 4/12/2007 10°F
16 4/12/2007 11°F
17 4/12/2007 11°F
18 4/12/2007 12°F
19 4/12/2007 13°F
20 4/12/2007 13°F
21 4/12/2007 14°F
22 4/12/2007 15°F
23 4/12/2007 15°F
24 4/12/2007 16°F
----------------------------------
Total temperature average:
my problem is, that i have been trying to use a counter to display the average and im stumped... simply put i have no idea how to do it and i cant seem to find information on how to do it anywhere. Heres the code i have done so far, any help or explanation is appreciated.
#include <iostream.h>
#include <fstream.h>
int Celsius(int); //Celsius conversion formula function
int main()
{
// Variables Setup
int ref, ctemp, myloop;
char mydate[9];
//File Management
ifstream inFile; //Input File Logical Name
ofstream outFile; //Output File Logical Name
inFile.open("H:\\1.dat"); //Input File Merge Setup
outFile.open("H:\\2.txt"); //Output File Merge Setup
inFile >> ref >> mydate >> ctemp; // Read File
//Headings
outFile << "\tCELCIUS TO FAHRENHEIT CONVERSION" << endl;
outFile << "\t";
for (myloop=1; myloop<35; myloop++)
{outFile << "-";} // Dash Line Print Cycle
outFile << endl;
outFile << "\tREF." << "\tDATE" << "\tCONVERSION" << endl << endl;
// End of Headings
while (inFile) //End-ofFile Controlled Loop
{
outFile << "\t" << ref << "\t" << mydate << "\t" << Celsius(ctemp)
<< "°F" << endl << endl; // Write Record
inFile >> ref >> mydate >> ctemp; // Read File
}
outFile << "\t";
for (myloop=1; myloop<35; myloop++)
{outFile << "-";} // Dash Line Print Cycle
outFile << endl;
outFile << "\tTotal temperature average:" << endl;
int number;
int average;
int count = 0;
{
ctemp += number;
count++;
}
average = ctemp / count;
return 0;
}
int Celsius(int ctemp) // Celsius to Fahrenheit Conversion Function
{
int ctof = 0;
ctof = (ctemp - 32) * 5/9;
ctemp = ctof;
return ctemp;
}