Created
November 26, 2015 04:17
-
-
Save ChrisOrozco97/1a592db27c1b41d7a474 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <fstream> | |
#include <sstream> | |
#include <string> | |
using namespace std; | |
int main (){ | |
string Read; | |
string MidPrice; | |
string CityMpg; | |
string HighMpg; | |
int n=57; | |
int i; | |
float city; | |
float AverageCity=0.0; | |
float high; | |
float AverageHigh=0.0; | |
float price; | |
float AveragePrice=0.0; | |
ifstream read_file("93cars.dat.txt"); | |
if (read_file.is_open()){ | |
for (i=0;i<93;i++){ | |
getline(read_file,Read); | |
MidPrice=Read.substr(42,4); | |
istringstream buffer(MidPrice); | |
buffer>>price; | |
CityMpg=Read.substr(52,2); | |
istringstream buffer2(CityMpg); | |
buffer2>>city; | |
HighMpg=Read.substr(55,2); | |
istringstream buffer3(HighMpg); | |
buffer3>>high; | |
AverageHigh= AverageHigh+high; | |
AveragePrice= AveragePrice+price; | |
AverageCity= AverageCity+city; | |
getline(read_file,Read); | |
} | |
read_file.close(); | |
} | |
else{ | |
cout<<"Cannot open the file, try again"<<endl; | |
} | |
AveragePrice= AveragePrice/93; | |
AverageCity= AverageCity/93; | |
AverageHigh= AverageHigh/93; | |
cout<<"Average midprice = "<<AveragePrice<<endl; | |
cout<<"Average City MPG = "<<AverageCity<<endl; | |
cout<<"Average Highway MPG = "<<AverageHigh<<endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment