делая это для задания, я не могу пройти мимо этого. Я пытаюсь прочитать значения из текстового файла. данные из файла имеют следующий формат:
int string string double string int double int string bool.
например строки (текстовый файл о страховых случаях с несколькими строками)
1 ДТП 26.01.2014 112049.26 Мужской 46 112049.00 2013 Красный 1
Мне нужно отсортировать значения сумм требований по цветам в файле и добавить их. затем выведите итоги.
До сих пор я не могу заставить свою программу правильно читать значения из файла, хотя не уверен, что я делаю неправильно.
Любые объяснения и указатели в правильном направлении относительно того, почему это может быть, будут оценены.
#include<iostream>
#include<iomanip>
#include<fstream>
#include<string>
#include<cmath>
using namespace std;
int main()
{
double claimTotalBlue=0;
double claimTotalRed=0;
double claimTotalWhite=0;
int blue=0;
int red=0;
int white=0;
double averagered;
double averageblue;
double averagewhite;
int menuchoice;
cout<<"1. Blue cars"<<endl;
cout<<"2. White cars"<<endl;
cout<<"3. Red cars"<<endl;
cout<<"4. Quit"<<endl;
cout<<"Enter your choice (1-4): ";
cin>>menuchoice;
cout<<endl;
cout<<setfill('-');
ifstream inFile;
inFile.open("claims.dat");
while (inFile)
{
int policyNumber, age, vehicleValue, yearOfManufacture, claimAmount;
string type;
string date;
string gender;
string colour;
bool immobilizer;
inFile>>policyNumber>>type>>date>>claimAmount>>gender>>age>>vehicleValue>>yearOfManufacture>>colour>>immobilizer;
if(colour==string("Blue"))
{
blue=blue++;
claimTotalBlue=claimTotalBlue+claimAmount;
}
if(colour==string("White"))
{
white=white++;
claimTotalWhite=claimTotalWhite+claimAmount;
}
if(colour==string("Red"))
{
red=red++;
claimTotalRed=claimTotalRed+claimAmount;
}
};
if(menuchoice==1)
{
averageblue=(claimTotalBlue/blue);
cout<<"Received "<<blue<<" claims in respect of blue cars"<<endl;
cout<<"The total value of claims in respect of blue cars is R "<<claimTotalBlue<<endl;
cout<<"The average value of claims in respect of blue cars is R "<<averageblue<<endl;
}
if(menuchoice==2)
{
averagewhite=(claimTotalWhite/white);
cout<<"Received "<<white<<" claims in respect of white cars"<<endl;
cout<<"The total value of claims in respect of white cars is R "<<claimTotalWhite<<endl;
cout<<"The average value of claims in respect of white cars is R "<<averagewhite<<endl;
}
if(menuchoice==3)
{
averagered=(claimTotalRed/red);
cout<<"Received "<<red<<" claims in respect of red cars"<<endl;
cout<<"The total value of claims in respect of red cars is R "<<claimTotalRed<<endl;
cout<<"The average value of claims in respect of red cars is R "<<averagered<<endl;
}
if(menuchoice==4)
{
return 0;
};
return 0;
}