Can't get the final score I want

I'm trying to output this:

Rank 1 422.30 Chen Ruolin 19 China
Rank 2 366.50 Brittany Broben 16 Australia
etc. (up to Rank 6)

But when I try to debug my code it gives me:

Rank 1 -92559631349317830000000000000000000000000000000.00 Chen Ruolin 19 China
etc. (the same numbers but different divers, age and country for the lines)

This is what I have so far (I know that final_score = final_score + answer; is wrong. I don't know how to fix that part.):

#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <string>
using namespace std;

void read_data(string country[], string diver_name[], int age[], int size, double diff, double score[], double final_score[]);
double sort_score(double score[], double diff);

int main()
{
string diver_name[6];
string country[6];
int age[6];
double final_score[6];
int size = 6;
double diff = 0;
double score[6];
cout << fixed << showpoint << setprecision(2);

read_data(country, diver_name, age, size, diff, score, final_score);



system("pause");
return 0;
}


void read_data(string country[], string diver_name[], int age[], int size, double diff, double score[], double final_score[])
{
ifstream dataIn;
dataIn.open("diving.txt");
if (dataIn.fail())
{
cout << "File does not exist." << endl;
system("pause");
exit(1);
}
int i, count;
double answer;
for (i = 0; i < size; i++) // diver
{
getline(dataIn, country[i]);
getline(dataIn, diver_name[i]);
dataIn >> age[i];

double total = 0;
for (count = 0; count < 5; count++) // dive
{
dataIn >> diff;
dataIn >> score[0];
dataIn >> score[1];
dataIn >> score[2];
dataIn >> score[3];
dataIn >> score[4];
dataIn >> score[5];
dataIn >> score[6];
answer = sort_score(score, diff);

}
dataIn.get();
}




int counter;
for (counter = 0; counter < 6; counter++)
{
cout << "Rank " << counter + 1 << ": " << final_score[counter] << " " << diver_name[counter] << " " << age[counter] << " " << country[counter] << endl;
}
dataIn.close();
}

double sort_score(double score[], double diff)
{
vector<double> judge(7);

judge[0] = score[0];
judge[1] = score[1];
judge[2] = score[2];
judge[3] = score[3];
judge[4] = score[4];
judge[5] = score[5];
judge[6] = score[6];

double temp;
int counter;
bool swap;

do
{
swap = false;
for (counter = 0; counter < 6; counter++)
{
if (judge[counter] < judge[counter + 1])
{
temp = judge[counter];
judge[counter] = judge[counter + 1];
judge[counter + 1] = temp;
swap = true;
}

}
} while (swap == true);

judge.pop_back();
judge.pop_back();
reverse(judge.begin(), judge.end());
judge.pop_back();
judge.pop_back();

double thisDive = (judge[0] + judge[1] + judge[2])*diff;
return thisDive;
}
Last edited on
Topic archived. No new replies allowed.