Okay I'm writing this simple program that asks for the names of three runners, then it asks for the time they finished the race. Based on the time they finished it orders them either first second or third.
The problem I am running into is that with the if statement. I wrote out ALL possible ways the order can come out. The code works fine but i want it to pick ONE if statement. I dont know how to write the code so that it picks just one of the combinations. Can anyone help me out?
#include <iostream>
#include "conio.h"
usingnamespace std;
int main()
{
char runner1[20], runner2[20], runner3[20];
double time1, time2, time3;
cout << "Enter the name of the first runner: ";
cin >> runner1;
cout << "Enter the name of the time of the first runner: ";
cin >> time1;
cout << "Enter the name of the second runner: ";
cin >> runner2;
cout << "Enter the time of the second runner: ";
cin >> time2;
cout << "Enter the name of the third runner: ";
cin >> runner3;
cout << "enter the time of the third runner: ";
cin >> time3;
if(time1 > time2 && time1 > time3 && time2 > time3) //123
cout << runner1 << " came in first place!" << endl;
cout << runner2 << " came in second place!" << endl;
cout << runner3 << " came in third place!" << endl;
//132
if(time1 > time2 && time1 > time3 && time3 > time2)
cout << runner1 << " came in first place!" << endl;
cout << runner3 << " came in second place!" << endl;
cout << runner2 << " came in third place!" << endl;
//213
if(time2 > time1 && time2 > time3 && time1 > time3){
cout << runner2 << " came in first place!" << endl;
cout << runner1 << " came in second place!" << endl;
cout << runner3 << " came in third place!" << endl;
}
//231
if(time2 > time3 && time2 > time1 && time3 > time1){
cout << runner2 << " came in first place!" << endl;
cout << runner3 << " came in second place!" << endl;
cout << runner1 << " came in third place!" << endl;
}
//312
if(time3 > time1 && time3 > time2 && time1 > time2){
cout << runner3 << " came in first place!" << endl;
cout << runner1 << " came in second place!" << endl;
cout << runner2 << " came in third place!" << endl;
}
//321
if(time3 > time2 && time3 > time1 && time2 > time1){
cout << runner3 << " came in first place!" << endl;
cout << runner2 << " came in second place!" << endl;
cout << runner1 << " came in third place!" << endl;
}
_getch();
}