Parallel Array help

Think I've got most of this complete but need a little help for current project. This is what it is supposed to do.
- Create two parallel arrays (one for trip number, the other for the final trip cost).
- Read in the file, calculates the final cost per trip
- Display all information to the monitor including new fuel cost and final trip cost
- Stores the trip number and calculated final trip cost in the arrays
- Creates an output file that will write the array in reverse sequence.
Pretty sure I've declared the arrays correctly because it is for up to 100 trips...same with final costs. Figured there could be 150 costs as well. Not sure how to take what is on the screen and get it into the arrays correctly.

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
  //Joe Snuffy
//Project 11
/*Program that reads in a .txt file and uses 
parallel arrays to hold data, output to display
and finally store data in revers in new .txt file*/

#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>

using namespace std;
int main()
{

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

//Variables
int tripNbr; // array to hold up to 200 trips
double finalCost; //array to hold up to 200 final costs
double fuelCost = 0;
double fuelTotal = 0;
double wasteDisp = 0;
double misCost = 0;

//create 2 arrays to hold output data
int trip[100];
double netCost[100];


cout<<"Welcome to Joe Snuffy Space Travel Company"<<endl;
cout<<endl;
cout<<"Trip No"<<setw(10)<<"Fuel"<<setw(10)<<"Waste"<<setw(10)<<"Misc"<<setw(15)<<"Discount Fuel"<<setw(15)<<"Final Cost"<<endl;

if(fileIn.fail())
{
	cout<<"File did not open."<<endl;
}
while(fileIn>>tripNbr>>fuelCost>>wasteDisp>>misCost)
{
	fuelTotal = fuelCost - (fuelCost * .10);
	finalCost = fuelTotal + wasteDisp + misCost;
	cout<<tripNbr<<setprecision(2)<<fixed<<setw(14)<<fuelCost<<setw(10)<<wasteDisp<<setw(10)<<misCost<<setw(15)<<fuelTotal<<setw(15)<<finalCost<<endl;

}



system("Pause");
return 0;
}
Topic archived. No new replies allowed.