2nd and 3rd place in my program

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
// Includes
#include "stdafx.h"
#include <iostream>
#include <stdio.h>
#include <conio.h>
using namespace std;

// Main Function
int main()
{
	char runner1[10], runner2[10], runner3[10];
	int rp1, rp2, rp3;

	cout << "This program displays and tells you what runner came in 1st, 2nd, or 3rd.\n\n";

	cout << "Enter runner1 name: ";
	cin >> runner1;
	cout << "Enter runner2 name: ";
	cin >> runner2;
	cout << "Enter runner3 name: ";
	cin >> runner3;
	cout << "Enter runner1 score: ";
	cin >> rp1;
	cout << "Enter runner2 score: ";
	cin >> rp2;
	cout << "Enter runner3 score: ";
	cin >> rp3;

	cout << "\n\n";

	if ( rp1 < rp2 && rp1 < rp3)
		cout << runner1 << " came in 1st place with a score of " << rp1 << endl;
	else if ( rp2 < rp1 && rp2 < rp3 )
		cout << runner2 << " came in 1st place with a score of " << rp2 << endl;
	else if (rp3 < rp1 && rp3 < rp2 )
		cout << runner3 << " came in 1st place with a score of " << rp3 << endl;

	_getch();

	return 0;
}



I am having some trouble on thinking how i am suppose to do this, displaying who came in first was no problem at all, now i am having trouble, i need help making this so when a runner comes in 1st i need it to display who came in 2nd and 3rd place as well, can someone help me with that.
You need to nest your if statements. Once you determine who is in first place in the above code, you can then continue to deermine who is in second and third.

BTW your if statements are wrong:

if(rp1 < rp2 && rp1 < rp3) //if runnerplace1 is less then runnerplace2 and runnerplace1 is less then runnerplace3. i don't think this is what you intended.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

//check if runner one came in first
if(rp1 > rp2 && rp1 > rp3)
{
    if(rp2 > rp3) //if he did, then check to see where runner2 and three placed
     {
        cout<<runner1<<" came in first with a score of "<<rp1<<endl;
        cout<<runner2<<" came in first with a score of "<<rp2<<endl;
        cout<<runner3<<" came in first with a score of "<<rp3<<endl;
     }
    else
     {
        cout<<runner1<<" came in first with a score of "<<rp1<<endl;
        cout<<runner3<<" came in first with a score of "<<rp3<<endl;
        cout<<runner2<<" came in first with a score of "<<rp2<<endl;
     }
}


then you do the same with the rest of them.
Thank you, it works now.
Topic archived. No new replies allowed.