I am setting up a program that will read multiple lines of data from an input file. I am able to get it to read the first line (there are 6 lines of data) but I can not get it to loop. Also I am unable to get the floor problem to work.
Any help would be appreciated! Thanks!

#include <fstream> // for file streams for input/output
#include <iomanip> // for formatting manipulators
#include <cmath> //added for rounding of bill
#include <math.h> //added for rounding of bill
#include <stdio.h> //added for rounding of bill
using namespace std;
void main() {
ifstream In("gases.dat"); // Open the input file.
ofstream Out("gases.dat"); // Open the output file.
Out << fixed << showpoint; // Enable floating-point output formatting.
double bill, // gas bill
average, // average $/meter^3
totalaverage, // total average
totalbill; // total bill
int current, // current reading
previous, // previous reading
totalused, // total used
used; // used gas amount 

// Initialize the totals:
totalaverage = 0.0;
totalbill = 0.0;
totalused = 0;
// Write the header information to the output file:
Out << "Previous  Current  Amount  Used  Gas Bill($)  Average $/meter^3" << endl;
Out << "----------------------------------------------------------------" << endl;
// Read prior information :
In.ignore(255, '\n'); // ignore header
In >> previous >> current;

//calculate gas amount used
used = current-previous;
//upate total amount used
totalused = totalused + used; 
//calculate bill amount
if (used >= 800)
	bill = 21.00+(used-300)*0.025;
else if (used >=600)
	bill = 21.00+(used-300)*0.04;
else if (used >300)
	bill = 21.00+(used-300)*0.06;
else 
	bill= 21.00;
//update total bill amount
totalbill = totalbill + bill;
//calculate average
average=bill/used;


//round gas bill to two digits
bill = floor(bill*100+0.5)/100.0;

//output information
Out <<previous<<" "<<" "<<" "<<" "<<" "<<" "<<" "<<" "<<current
<<" "<<" "<<" "<<" "<<" "<<" "<<" "<<" "<<used
<<" "<<" "<<" "<<" "<<" "<<" "<<" "<<" "<<bill
<<" "<<" "<<" "<<" "<<" "<<" "<<" "<<" "<<average << endl;

Out << "----------------------------------------------------------------" << endl;
Out << "Totals:               " <<totalused
<<" "<<" "<<" "<<" "<<" "<<" "<<" "<<" "<<totalbill
<<" "<<" "<<" "<<" "<<" "<<" "<<" "<<" "<<totalaverage << endl;

// Close the input and output files:
In.close();
Out.close();
}

It's not looping because you haven't written any loops.

Read this.

With your lack of formatting I must be missing the for , do-while , or while statements that start your loop

I'm sorry I am new to C++ and this is my first starting from scratch program. If there is any "hints" or websites you can give me on where to find help on creating a loop and such please share.

Did you follow the links we gave you? For some reason, I doubt it.

Allow me to try again...

Click here to read this...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.