Not displaying data from file.

The input data is.
1
2
3
4
5
6
7
8
9

111 //trip number 1
100.00 //fuel cost
200.00 //waste disposal
50.00 // miscellaneous expense
222 //trip number 2 
200.00 //fuel cost 
300.00 //waste disposal 
100.00 //miscellaneous expense 


Yet, when I run this it does not display that data and calculate the the problem. Anyone see the error I made? Visual Studio hasn't pointed anything out yet.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
 
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>

using namespace std;
int main()
{

	//create two arrays
	const int ARRAY_SIZE = 200; //array size of 100 elements
	int nbrTrips[ARRAY_SIZE]; //array declaration of 100 elements
	int counter; //For loop counter variable

	double totalCost[ARRAY_SIZE]; //array declaration for cost of trips

	//Variables
	
	double fuelCost;
	double fuelTotal;
	double wasteDP;
	double misCost;
	double finalCost = 0.0;
	string tripNbr;

	ifstream fileIn; //create the file object 
	ofstream fileSave; //create a new output file
	fileIn.open("TripInput.txt"); //reads in the file
	fileSave.open("TripCost.txt"); //opens the output file

	cout << "Welcome to " << endl;
	cout << endl;
	cout << "Trip No" << setw(10) << "Fuel" << setw(10) << "Waste" << setw(10) << "Misc" << setw(19)
		<< "Discount Fuel" << setw(15) << "Final Cost" << endl;

	if (fileIn.fail())//tests to see if the file has opened
	{
		cout << "File did not open" << endl;
	}
	while (fileIn >> tripNbr >> fuelCost >> wasteDP >> misCost) //while loop. Reads in data from file TripInput
	{
		fuelTotal = fuelCost - (fuelCost * .10);
		finalCost = fuelTotal + wasteDP + misCost;
		cout << tripNbr << setprecision(2) << fixed << setw(14) << fuelCost << setw(10) << wasteDP
			<< setw(10) << misCost << setw(15) << fuelTotal << setw(15) << finalCost << endl;

		for (counter = 0; counter < ARRAY_SIZE; counter++) 
		{
			nbrTrips[counter] = counter; // array 1
			totalCost[counter] = counter; // array 2
		}

		for (counter = 0; counter < ARRAY_SIZE; counter++) //use for loop to output to file
		{
			fileSave << nbrTrips[ARRAY_SIZE - 1 - counter];
			fileSave << '\t';
			fileSave << totalCost[ARRAY_SIZE - 1 - counter] << endl;
		}
		fileSave.close();
	}
	system("Pause");
	return 0;
}





does your input data need to have the comments?
or can you remove them?
Doesn't need comments. Thanks.
Last edited on
Topic archived. No new replies allowed.