Need Help with If Statement

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?

Heres the code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <iostream>
#include "conio.h" 


using namespace 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();
}


THis is whats coming out when i compile it.

http://i.imgur.com/Pfm5a.png

But I want it to only say the correct if statement.
but i want to fix it so it says

Danny came in first place!
Justin came in second place!
Ace came in third place!

Can anyone help? thanks in Advance!
Every if looks for an else. If an if doesn't have an else, weird things can happen.

Also, inside the if (/*items*/), each inequality needs to be grouped in parentheses. Otherwise the logic is:
if (time1 > time2 && time1 > time3 && time2 > time3)
/*if time1 > time2/* if (1 && time1 > time3 && time2 > time3)

etc, and then unless the times are 1, the logic falls apart.

So, format your ifs like:
if((time1 > time2) && (time1 > time3) && (time2 > time3))
Topic archived. No new replies allowed.