sorting nos in an array and recognising nos that are the same

I'm trying to sort arrays. The problem whenever it was working was that if my crawl times were the same it would just take one number rather than giving both numbers first. If this makes sense. Had wondered whether I should make a separate first, second and third variable. Think I am over complicating things would be really grateful for any feedback have been at this for days and very little to show for it

#include "stdafx.h"
#include <conio.h>
#include <iostream>
#include <Windows.h>
#include <iomanip>
#include <string>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
string competitors[10] = { "David", "Chris", "Daley", "luke", "Antonio", "Micheal", "Juan", "Wayne", "Paul", "Marcus" };
int crawlTimes[10];
int crawlTimeOrder[10];
int i = 0, j = 0, temp = 0;
int backStrokeTimes[10];
int backStrokeTimeOrder[10];
int bufferFlyTimes[10];
int bufferFlyTimeOrder[10];
string disqualified;
bool invalid;

system("Color 1E");


for (int i = 0; i <= 9; i++)
{
cout << competitors[i] << ":";
cout << " \n\tCrawl time: ";
cin >> crawlTimes[i];
}

for (int i = 0; i <= 9; i++)
{

crawlTimeOrder[i] = i;
}

for (i = 0; i <= 9; i++)

{

for (j = i + 1; j <= 9; j++)
{
if (crawlTimes[crawlTimeOrder[i]] > crawlTimes[crawlTimeOrder[j]])
{
temp = crawlTimeOrder[i];
crawlTimeOrder[i] = crawlTimeOrder[j];
crawlTimeOrder[j] = temp;
}
}
}

cout << "1st Place:" << competitors[crawlTimeOrder[0]] << " " << crawlTimes[crawlTimeOrder[0]] << " " << "2nd Place:" << competitors[crawlTimeOrder[1]] << " "
<< crawlTimes[crawlTimeOrder[1]] << " " << "3rd Place:" << competitors[crawlTimeOrder[2]] << " "<< crawlTimes[crawlTimeOrder[2]] << " ";


Last edited on
Topic archived. No new replies allowed.