I'm supposed to output a program that comes out like this:
http://img638.imageshack.us/img638/4135/screen3t.jpg
And here is the top part of the code. It is supposed to read a .txt file that has the numbers of the: flight; passengers; and miles;
int flight, passengers, miles;
float income, cost, profit, base, fuel;
ifstream airline;
ofstream outfile;
airline.open("airline.txt");
outfile.open("outair.txt");
And here are the equations on how we are supposed to calculate the income; cost; and profit;
Here is the equation part of the code:
if (miles>>1000)
{
income=1.2*base*passengers;
cost=1.25*miles*6.50;
}
if (miles>=200 || miles<=1000)
{
income=1.4*base*passengers;
cost=1.5*miles*6.50;
}
if (miles<<200)
{
income=1.6*base*passengers;
cost=2*miles*6.50;
}
profit=income-cost;
And here is the .txt (airline.txt) file that it is reading:
Flight # Passengers Miles Traveled
1001 125 600
1002 105 1200
1004 134 150
1005 240 1500
1010 125 400
1011 99 115
1012 140 750
1013 250 1350
But the problem is that I have no idea how to declare what the passengers, miles, flight # are according to the .txt file. I'm not sure how it takes all the numbers from the .txt file and be able to implement in the equation.
Every time I do it I just get a complete mess of numbers that have no rhyme or reason to why they are being outputted. Here is the entire code that I have:
using namespace std;
#include <iostream>
#include <iomanip>
#include <fstream>
int main()
{
int flight, passengers, miles;
float income, cost, profit, base, fuel;
ifstream airline;
ofstream outfile;
airline.open("airline.txt");
outfile.open("outair.txt");
airline >> flight
>> passengers
>> miles;
cout <<left <<setprecision(2) <<fixed;
cout <<"Please Enter Base Fare" <<endl;
cin >> base;
cout <<"Please Enter Fuel Cost" <<endl;
cin >> fuel;
cout <<endl <<endl;
cout <<right <<setprecision(2)<<fixed;
cout <<setw(10) <<"Flight"
<<setw(10) <<"Income"
<<setw(10) <<"Cost"
<<setw(10) <<"Profit" <<"\n\n";
outfile<<right <<setprecision(2)<<fixed;
outfile<<setw(10) <<"Flight"
<<setw(10) <<"Income"
<<setw(10) <<"Cost"
<<setw(10) <<"Profit" <<"\n\n";
while ( ! airline.eof())
{
airline >> flight
>> passengers
>> miles;
if (miles>>1000)
{
income=1.2*base*passengers;
cost=1.25*miles*6.50;
}
if (miles>=200 || miles<=1000)
{
income=1.4*base*passengers;
cost=1.5*miles*6.50;
}
if (miles<<200)
{
income=1.6*base*passengers;
cost=2*miles*6.50;
}
profit=income-cost;
cout << setw(10) <<flight <<" "
<< setw(10) <<income <<" "
<< setw(10) <<cost <<" "
<< setw(10) <<profit <<endl;
outfile << setw(10) <<flight <<" "
<< setw(10) <<income <<" "
<< setw(10) <<cost <<" "
<< setw(10) <<profit <<endl;
airline.close();
outfile.close();
}
return 0;
}
I'm really just lost now, and I need help as soon as possible. Hopefully you guys can help me and understand all this mess...because I have no idea anymore. And my code is probably all wrong now, but it worked for the first assignment...but not anymore :@
Thanks!