i am trying to find a way to read a file and perform mathematics on the numbers dose anyone know how i should proceed on this.
#include "stdafx.h"
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
struct car
{
int car_no;
int milesDr;
int gallons;
};
int main()
{
const int reports = 5;
int temp_mpg = 0;
int goallonsTotal = 0;
int miles_total = 0;
car records[reports] =
{
{25, 1450, 62},
{36, 3240, 136},
{44, 1769, 67},
{52, 2360, 105},
{68, 2115, 67}
};
cout << endl;
cout << setiosflags(ios::left);
for (int i = 0; i < reports; i++)
{
cout << setw(8)<<"Car ID: " << records[i].car_no;
cout << setw(18)<<" Miles per gallon: "<< records[i].milesDr/records[i].gallons << endl;
temp_mpg += records[i].milesDr/records[i].gallons;
}
cout << "Average miles per gallon of fleet is: " << temp_mpg/reports << endl;
system ("pause");
return 0;
}
the above data in this program will need to be read from a file and do the same thing.
where should i go to find the answers to this solution, i don't think i need any code from anyone but a good resource to educate myself will be of great help and much appreciated.
thanks guys.
This post has been edited by Omegaclass: 13 December 2009 - 08:11 PM

New Topic/Question
Reply




MultiQuote







|