Trouble executing order correctly

I've got an assignment for my C++ class which basically goes like this: Write a program which will accept the names and finish times of 3 racers, and will determine and display their finish order. You may assume that there are no ties, i.e. no one has a duplicate finish time.

My final output keeps coming up messed up, can anyone give me a better idea of what i might be doing wrong?

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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
 //  Header Comments
//  Header Comments

#include <iostream>
#include <cmath>
using namespace std;

int main()
{
    // Declare Variables
    string runner_1;
    string runner_2;
    string runner_3;
    int run_time1 = 0;
    int run_time2 = 0;
    int run_time3 = 0;
        
    // Program Logic
    
    //first
    cout << "What is the first runner's name: ";
    cin >> runner_1;
    
    cout << "What was " << runner_1 << "'s time, in seconds: " ;
    cin >> run_time1;
    
    //second
    cout << "What is the second runner's name: ";
    cin >> runner_2;
    
    cout << "What was " << runner_2 << "'s time, in seconds: " ;
    cin >> run_time2;
    
    //third
    cout << "What is the third runner's name: ";
    cin >> runner_3;
    
    cout << "What was " << runner_3 << "'s time, in seconds: " ;
    cin >> run_time3;
    
    //end endered info
    
    //start calculating winner
    
    if ( run_time1 > run_time2 && run_time1 > run_time3 )
        {
            cout << " 1st place: " << runner_1;
        }
        if ( run_time2 > run_time3 )
        {
            cout << " 2nd Place: " << runner_2;
            cout << " 3rd Place: " << runner_3;
        }
      else;
        //second
    if ( run_time2 > run_time1 && run_time2 > run_time3)       
        {
            cout << " 1st place: " << runner_2;
        }
        if ( run_time1 > run_time2 )
        {
            cout << " 2nd Place: " << runner_1;
            cout << " 3rd Place: " << runner_3;
        }
        else;
        //third 
    if ( run_time3 > run_time1 && run_time3 > run_time2)       
        {
            cout << " 1st place: " << runner_3;
        }
        if ( run_time2 > run_time1 )
        {
            cout << " 2nd Place: " << runner_2;
            cout << " 3rd Place: " << runner_1 << endl; 
        }
            
            
        
    system("pause");    
    return 0;
}

 
Your if statements doesn't match your indentation. Look where you have placed the { }.
The semicolon after else means it should do nothing in the else case which is probably not what you want.

I also think you have forgot to handle all the possibilities. Consider the case when run_time1 > run_time3 > run_time2. You don't handle that case.

Thank you, ill add that in and see how it goes.
Topic archived. No new replies allowed.