arrays

I am trying to take an input of different speeds from athletes and then display the fastest, the slowest, the speeds under 5:00, and the average. The times are inputted by mins seconds[enter]. The output should be in mins:seconds and should be displayed as: The fastest time is #2 at 4:03. My issue is that I can't figure out how to get the function to display the time correctly and to display the specific athlete number before it like it is supposed to be displayed.

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
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

void displayTime(int totalSeconds); //Function call to display seconds

 

int main()
{
	const int ATHLETES = 10;
	int totalSeconds[ATHLETES];
	int  count, slowest, fastest, average,
		 total=0; 
  
cout << "Please enter all athlete's times in minutes and seconds separated by a space." << endl;

	for (count = 0; count < ATHLETES; count++) // loop for athlete speed input.
	{
		int total = 0;
		int minutes = 0;
		int seconds = 0;
		
		cout << "Athelete " << (count + 1) << ":";

		cin >> minutes;
		cin >> seconds;

		total = seconds + (minutes * 60);
		totalSeconds[count] = total;
		
		}

	displayTime(totalSeconds[count]); 

	fastest = totalSeconds[0]; // fastest loop speed
	for (count = 1; count < ATHLETES; count++)
			if (totalSeconds[count] < fastest)
			fastest = totalSeconds[count];
		
			cout << "Fastest time = " << fastest << endl;
	
	lowest = totalSeconds[0]; // slowest loop speed
	for (count = 1; count < ATHLETES; count++) 
				if (totalSeconds[count] > slowest)
			slowest = totalSeconds[count];
	
		cout << "Slowest Number = " << slowest << endl;
	

	

	for (int count = 0; count < ATHLETES; count++) // average speed loop
	
		total += totalSeconds[count];
		average = total / ATHLETES;
		

		cout << "The average speed is " << average << endl;
	

	system("PAUSE");
	return 0;
}


void displayTime(int totalSeconds)
{

	int minutes,
	    seconds;
		
	minutes = totalSeconds / 60;
	seconds = totalSeconds & 60;
	
	
}


Any help will be appreciated.
Last edited on
You have a void function meaning it return no value so within your display function there should be a cout statement. Not sure if i understood the question correctly
I apologize I had augmented this earlier and had taken it out out. The main point was I am trying to get athletes number into a variable so I can display it. Like,
"The fastest speed belongs too " << fastest_Athlete << "and his speed is " << fastest << endl;
so you have 10 athletes in your array and you want to determine which one is the fastest and display the speed? You wouldnt be able to display a name only the location in the array of the fastest time. But to determine who is the fastest just declare a variable called fastestAthlete = totalseconds[0] ; then create a for loop to cycle through your array. Within your for loop should be an if statement which checks to see if the time is faster than the time store in fastestAthlete If thats true then fastestAthlete = totalSeconds[i];

Hope i explained that well enough!
Here is a rough example i pulled from one of my projects

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//
//************************************
//searchLowestCard assistant Function*
//************************************
//
CardTemplate searchLowestCard(vector<CardTemplate> playerHand)
{
    CardTemplate lowestCard = playerHand[0];
    for(int i = 0; i < playerHand.size(); i++)
    {
        if(playerHand[i].cardNum < lowestCard.cardNum && playerHand[i].suitStrength < lowestCard.suitStrength)
        {
            lowestCard = playerHand[i];
        }
    }
    return lowestCard;
}
Thanks I just saw this. It helped and I am currently working on rewriting this program to get a better understanding I appreciate you help.
Glad it helped! I was worried it might have too much extra stuff going on to easily understand it. Feel free to ask any questions you may have!
Topic archived. No new replies allowed.