problem with my code

I don't understand why something isn't working on my code. I have the dat file and the cpp in the same folder
this is the problem:
Write an interactive c++ program whose input (from a file) is a series of 12 temperaturess. It should write out on file tempdata.dat each temperature as well as the difference between the current temperature and the one preceeding it. The difference is not output for the first temperature that is input. At the end of the program, the average temperature should be displayed for the user via cout. Here is my code:


#include <iostream>
#include <fstream>

using namespace std;
int main()
{
float t1;
float t2;
float t3;
float t4;
float t5;
float t6;
float t7;
float t8;
float t9;
float t10;
float t11;
float t12;
ofstream tempdata;
ifstream intemp;

float dift1t2;
float dift2t3;
float dift3t4;
float dift4t5;
float dift5t6;
float dift6t7;
float dift7t8;
float dift8t9;
float dift9t10;
float dift10t11;
float dift11t12;
float tempAvg;

intemp.open("intemp.dat");
tempdata.open("tempdata.dat");

intemp >> t1 >> t2 >> t3 >> t4 >> t5 >> t6 >> t7 >> t8 >> t9 >> t10 >> t11 >> t12;

dift1t2 = t1-t2;
dift2t3 = t2-t3;
dift3t4 = t3-t4;
dift4t5 = t4-t5;
dift5t6 = t5-t6;
dift6t7 = t6-t7;
dift7t8 = t7-t8;
dift8t9 = t8-t9;
dift9t10 = t9-t10;
dift10t11 = t10-t11;
dift11t12 = t11-t12;
tempAvg = (t1+t2+t3+t4+t5+t6+t7+t8+t9+t10+t11+t12)/12;

tempdata << t1 << ' ' << endl << t2 << ' ' << dift1t2 << endl << t3 << ' ' << dift2t3 << endl << t4 << ' ' << dift3t4 << endl << t5 << ' ' << dift4t5 << endl << t6 << ' ' << dift5t6 << endl << t7 << ' ' << dift6t7 << endl << t8 << ' ' << dift7t8 << endl << t9 << ' ' << dift8t9 << endl << t10 << ' ' << dift9t10 << endl << t11 << ' ' << dift10t11 << endl << t12 << ' ' << dift11t12;

cout << "The Average Temperature is " << tempAvg;

intemp.close();
tempdata.close();
return 0;
}
[code] "Use code tags" [/code]
why something isn't working on my code.
¿something? ¿what is the error?

About your code, you don't actually need to store all the temperature values. However if you want to do that, then learn about arrays.
Topic archived. No new replies allowed.