I have an assignment where i have to to determine ranks of 5 runners according to their times that were input. The only way of doing this that I know is by using if and else if statements. and I think there are over 120 permuations for 12345 so how do i determine the ranks of 5 people when there are over 120 permuations? Does C++ have way of making this easier. Im very new to this and any help would be appreciated. Thank you!


#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
int main()
{
ofstream outputfile;
outputfile.open("c:\\Project_2\\M20349431_output_2.txt");
ifstream infile;
infile.open("c:\\Project_2\\M20349431_output_2.txt");

//Define variables
const int SIZE = 21;
char name1[SIZE], name2[SIZE], name3[SIZE], name4[SIZE], name5[SIZE];
double time1, time2, time3, time4, time5;

//Display the purpose oof this program
cout<<"This program will determine the ranks of 5 runners according to their time."<<endl;
cout<<endl;

//Request the names and times of each runner.
cout<<"1. Enter the name of the runner"<<endl;
cin.getline(name1, SIZE);
cout<<endl; //For line spacing


cout<<"2. Enter the name of the next runner"<<endl;
cin.getline(name2, SIZE);
cout<<endl; //For line spacing

cout<<"3. Enter the name of the next runner"<<endl;
cin.getline(name3, SIZE);
cout<<endl; //For line spacing

cout<<"4. Enter the name of the next runner"<<endl;
cin.getline(name4, SIZE);
cout<<endl; //For line spacing

cout<<"5. Enter the name of the next runner"<<endl;
cin.getline(name5, SIZE);
cout<<endl; //For line spacing



//Request the time of each runner
cout<<"Enter the time for "<<name1<<endl;
cin>>time1;

if(time1 <= 0) //Check for negative numbers or 0)
{ cout<<"Error! Invalid number. You must enter a number greater than 0"<<endl; //Display "Error" message if a invalid number is entered
cin>>time1;
}

cout<<endl; //For line spacing


cout<<"Enter the time for "<<name2<<endl;
cin>>time2;

if(time2 <= 0) //Check for negative numbers or 0)
{
cout<<"Error! Invalid number. You must enter a number greater than 0"<<endl; //Display "Error" message if a invalid number is entered
cin>>time2;
}

cout<<endl; //For line spacing

cout<<"Enter the time for "<<name3<<endl;
cin>>time3;

if(time3 <= 0) //Check for negative numbers or 0)
{
cout<<"Error! Invalid number. You must enter a number greater than 0"<<endl; //Display "Error" message if a invalid number is entered
cin>>time3;
}

cout<<endl; //For line spacing

cout<<"Enter the time for "<<name4<<endl;
cin>>time4;

if(time1 <= 0) //Check for negative numbers or 0)
{ cout<<"Error! Invalid number. You must enter a number greater than 0"<<endl; //Display "Error" message if a invalid number is entered
cin>>time4;
}

cout<<endl; //For line spacing

cout<<"Enter the time for "<<name5<<endl;
cin>>time5;

if(time1 <= 0) //Check for negative numbers or 0)
{ cout<<"Error! Invalid number. You must enter a number greater than 0"<<endl; //Display "Error" message if a invalid number is entered
cin>>time5;
}

cout<<endl; //For line spacing



//Determine the rank of each runner according to the times that were entered



if(time1 < time2 && time2 < time3 && time3 < time4 && time4 < time5)
{
outputfile<<"\nThe ranks of the runners according to their times\n";
outputfile<<"---------------------------------------------------\n";

outputfile<<"Rank 1 is "<<setw(25)<<name1<<" With the time of: "<<setw(6)<<time1<<endl;

outputfile<<"Rank 2 is "<<setw(25)<<name2<<" With the time of: "<<setw(6)<<time2<<endl;

outputfile<<"Rank 3 is "<<setw(25)<<name3<<" With the time of: "<<setw(6)<<time3<<endl;

outputfile<<"Rank 4 is "<<setw(25)<<name4<<" With the time of: "<<setw(6)<<time4<<endl;

outputfile<<"Rank 5 is "<<setw(25)<<name5<<" With the time of: "<<setw(6)<<time5<<endl;
}

else if(time5 < time4 && time4 < time3 && time3 < time2 && time2 < time1)
{
outputfile<<"\nThe ranks of the runners according to their times\n";
outputfile<<"---------------------------------------------------\n";

outputfile<<"Rank 1 is "<<setw(25)<<name5<<" With the time of: "<<setw(6) <<time5<<endl;

outputfile<<"Rank 2 is "<<setw(25)<<name4<<" With the time of: "<<setw(6)<<time4<<endl;

outputfile<<"Rank 3 is "<<setw(25)<<name3<<" With the time of: "<<setw(6)<<time3<<endl;

outputfile<<"Rank 4 is "<<setw(25)<<name2<<" With the time of: "<<setw(6)<<time2<<endl;

outputfile<<"Rank 5 is "<<setw(25)<<name1<<" With the time of: "<<setw(6)<<time1<<endl;
}

and so on....... But then I realized there are about 120 permuations for 12345 and i would have to repeat this process over 120 times Is their an easier way to determine ranks, or do i have to do this 120 times. Please help