# this code calculates "Diving scores". My problem is two fold, one- if the contestants

Printable View

• 04-30-2003
Mule
this code calculates "Diving scores". My problem is two fold, one- if the contestants
OK thanks, take 2:
This code calculates "Diving scores". My problem is two fold, one- if the contestants are in a tie, they need to be outputed in alphabetical order; two, because they are tied they share the position in the tier and then you continue with the order minus the position one of the tied contestants would take, i.e. let's say there ar 6 contestants 2 ties for 2nd place. the order should be: 1, 2, 2, 4, 5 6.

Code:

```#include <iostream> #include <string> #include <fstream> #include <iomanip> using namespace std; const int ND = 3; //Number of dives const int NJ = 9; //Number of judges struct divers { string name; float dtotal [ND]; float ftotals; }; int main() { divers all_divers[20]; int ndiv, min, i, j, k, num, q, aa, bb, cc; float dd, js, s, x, total, small, large; js = 0; dd = 0, q = 0; num = 1; small = 10.0; large = 0.0; total = 0.0; divers temp; string temp1; cout << "RANK" << right << setw(10) << "NAME" << '\t' << '\t' ; for ( i = 0; i < ND; i++) { cout << " DIVE " << i + 1<< '\t' << '\t'; } cout << setw(4) << "TOTAL" << endl; cout << "-------------------------------------------------------------------------------"<< endl; while (fin >> ndiv) { if (ndiv != 0) { for ( i = 0; i < ndiv; i++) { all_divers[i].ftotals = 0.0; } for ( i = 0; i < ND; i++) { for (j = 0; j < ndiv; j++) { fin >> all_divers[j].name >> dd; for (k = 0; k < NJ; k++) { fin >> js; total += js; if (js < small) { small = js; } if (js > large) { large = js; } } total = total - (small + large); all_divers[j].dtotal[i] = dd * total; all_divers[j].ftotals += all_divers[j].dtotal[i]; total = 0.0; small = 10.0; large = 0.0; } } cout << fixed << showpoint; for (i = 0; i < ndiv; i++) { min = i; for ( j = i+1; j < ndiv; j++) { if (all_divers[j].ftotals > all_divers[min].ftotals) min = j; } temp = all_divers[i]; all_divers[i] = all_divers[i] = all_divers[min]; all_divers[min] = temp; } // This is the problem area. for ( i = 0; i < ndiv; i++) { if ( all_divers[i].ftotals == all_divers[i+1].ftotals) { num = num; for(aa = 0; aa <= ndiv; aa++) { bb = aa; for (cc = aa + 1; cc <= ndiv ; cc++) { if (all_divers[i].name > all_divers[bb].name) bb = cc; } } temp1 = all_divers[i].name; all_divers[i].name = all_divers[bb].name; all_divers[bb].name = temp1; cout << setfill('0') << setw(2) << setfill(' ') << num << right << setw(12) << all_divers[i].name << '\t'; } else { cout << setfill('0') << setw(2) << setfill(' ') << num << right << setw(12) << all_divers[i].name << '\t'; num++; } //It ends here for ( j = 0; j < ND; j++) { cout << right << setw(14) << setprecision(2) << all_divers[i].dtotal[j] << '\t'; } cout << setw(13) << setprecision(2) << all_divers[i].ftotals << endl; } num = 1; cout << endl; cout << " ************************************************** *****************************" << endl <<endl; } if (ndiv == 0) cout <<endl; } return 0; }```
• 04-30-2003
LuckY
tips
1) Please edit your post and insert a
[code]
before your source and a
[/code]
after it to preserve your formatting. It makes it so much easier to read/understand...

2) next post, try to use a better subject title to describe what your post is in regards to.. using the first few words from the post itself is not preferred.

thanks

[EDIT]
:eek: Oh, my, god... You did use code tags... I, uh... eesh....
Don't you format your source code????
• 04-30-2003
PJYelton
Also, you need to tell us more about your program, like where the error is, what it is doing wrong, what you have tried to do to solve the problem, your ideas, etc. Don't just say my program needs to do such-and-such and expect people to dive into all your code and write the relevant code for you.
• 04-30-2003
Mule
Alphabetizing
I'm too rushed trying to put these messages out, not thinking of what I need to say, need to show, and even how to say it.
Let me try this again some other time.