I am currently trying to do an assignment where I read in from a file, three variables from each line, add them together and then at the end basically add each column up.
We have to use classes.
Reading works, adding each line works, and writing all that to a file works.
However, adding each individual column gets me some really crazy and crappy stuff.
I have tried doing it with temp variables in my class, temp variables in my loop and out of my loop.
I either get odd results like “-9.25596e+061” or, results that appear to have worked correct but completely bad math.
Right now my code might look a little messy, because well I have tried 15 different things, and having to change stuff so much I did not want to waste the time of typing lots of nice comments and descriptive variable names. And right now my output it kinda messy, but it is pointless cleaning that up unless I can get it to add correct!
Here is my code:
As you will see some things commeted out that I tried.
using namespace std;
SalesFigures(double jan, double feb, double march_);
void math(double in, double in2, double in3);
// double temp1, temp2, temp3;
while (! in_stream.eof())
in_stream >> in_1 >> in_2 >> in_3;
one =SalesFigures(in_1,in_2,in_3) ;
// temp1 = in_1 + temp1;
// temp2 = in_2 + temp2;
// temp3 = in_3 + temp3;
// ofstream out_f;
// out_f << temp1 << " " << temp2 << " " << temp3;
SalesFigures::SalesFigures(double jan, double feb, double march_)
january = jan;
febuary = feb;
march = march_;
january = 0;
febuary = 0;
march = 0;
jan_total = 0;
feb_total = 0;
march_total = 0;
out_f << january << " " << febuary << " " << march << " " << january + febuary + march << endl ;
void SalesFigures::math(double in, double in2, double in3)
jan_total = (in + january);
feb_total = (in2 + febuary);
march_total = (in3 + march);
out_f << jan_total << " " << feb_total << " " << march_total << " " << jan_total + feb_total + march_total << endl ;
The source file is currently hardcoded to source.txt, here is an example of it:
Any help would be much appericated!
105.1 298.3 37998.4
644.9 5654.8 6654.2
65457.1 86465.1 96454.1