Display which array element holds smallest value

The code takes 12 user entered music track times, mins and seconds separated by a space. Turns it into total amount of seconds. I then need it to display which track # is the smallest and largest and the total seconds entered.

Example output would be:
Track 1: 2 13 (2 13 is user entered)
Track 2: 5 11
Track 3:
etc,......

The lowest value of the tracks is: #4 at 1:12

I have it displaying the highest and lowest total seconds but i am not sure how to get the track number to display.
I know my code doesn't put the time in this format but I will work on that next. I just have NO IDEA how to get the #4 to display.

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
#include <iostream>;
#include <iomanip>;  //will be used later in a function

using namespace std;
int main()
{
	const int TWELVE_INTEGERS = 12; // number of integers
	int tracks[TWELVE_INTEGERS]; // integers
	int min, sec, count; // loop counter

	// Get the 12 tracks from the keyboard

	cout << "Welcome to my Album Length Calculator\n";
	cout << "Please enter all track lengths in minutes and seconds separated by a space.\n\n";

	for (count = 0; count < TWELVE_INTEGERS; count++)
	{
		cout << "Tracks " << (count + 1) << ": ";
		cin >> min >> sec;
		tracks[count] = min * 60 + sec;
		//cin >> tracks[count];
	}
	
	// Display the highest value of the integers entered

	int high; // datatype for highest integer value 
	high = tracks[0];

	for (count = 0; count < TWELVE_INTEGERS; count++)
	{
		if (tracks[count] > high)
			high = tracks[count];

	}
	cout << "\nThe highest value of the tracks entered is: " << "at" << high << endl;


	// Display the lowest value of the integers entered
	int low = tracks[0]; // datatype for the lowest integer value

	for (count = 0; count < TWELVE_INTEGERS; count++)
	{
		if (tracks[count] < low)
			low = tracks[count];
	}

	cout << "The lowest value of the tracks entered is: " << "at" << low << endl;

	//to get sum            *****still in seconds
	double sum = 0;

	for (int count = 0; count < 12; count++)
	{

		sum += tracks[count];
	}
	cout << endl << "The sum length of the album is: " << sum << endl;

	//to get the average     ****Still in seconds
	long double average;
	double total = 0;

	for (count = 0; count < TWELVE_INTEGERS; count++)
		total += tracks[count];
	{
		average = total / TWELVE_INTEGERS;
	}
	cout << "The average length of a track is: " << average << endl;

	system("pause");
	return 0;
}
Last edited on
Hi =]

Your logic is sound, just a few typos and oversights. Below is what I got:
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
84
85
86
87
88
89
90
#include <iostream>;
#include <iomanip>;  //will be used later in a function

using namespace std;

int main()
{
	const int TWELVE_INTEGERS = 12; // number of integers
	int tracks[TWELVE_INTEGERS]; // integers
	int min,
		sec,
		count, // loop counter
		// EDIT added lowIndex
		lowIndex,
		// EDIT added highIndx
		highIndex;

	// Get the 12 tracks from the keyboard
	cout << "Welcome to my Album Length Calculator\n" 
		 << "Please enter all track lengths in minutes and seconds separated by a space.\n\n";

	for (count = 0; count < TWELVE_INTEGERS; count++)
	{
		cout << "Tracks " << (count + 1) << ": ";
		cin >> min >> sec;
		// EDIT put (min * 60) in parenthesis because the order of operations scares me
		tracks[count] = (min * 60) + sec;
		//cin >> tracks[count];
	}

	// Display the highest value of the integers entered
	int high = tracks[0]; // datatype for highest integer value 
	    highIndex = 0;

	for (count = 0; count < TWELVE_INTEGERS; count++)
	{
		// EDIT added highIndex = count
		if (tracks[count] > high) {
			high = tracks[count];
			highIndex = count;
		}
	}
	cout << "\nThe highest value of the tracks entered is: " << high << "at" << highIndex << endl;

	// Display the lowest value of the integers entered
	int low = tracks[0]; // datatype for the lowest integer value
		lowIndex = 0;

	for (count = 0; count < TWELVE_INTEGERS; count++)
	{
		// EDIT added lowIndex = count
		if (tracks[count] < low) {
			low = tracks[count];
			lowIndex = count;
		}
	}

	cout << "The lowest value of the tracks entered is: " << low << "at" << lowIndex << endl;

	//to get sum            *****still in seconds
	double sum = 0;

	for (int count = 0; count < 12; count++)
	{

		sum += tracks[count];
	}
	cout << endl << "The sum length of the album is: " << sum << endl;

	//to get the average     ****Still in seconds
	long double average;
	double total = 0;

	//**************Your Code**************************
	//for (count = 0; count < TWELVE_INTEGERS; count++)
	//	total += tracks[count];  // EDIT This statement is before the opening brace
	//{  
	//	average = total / TWELVE_INTEGERS;
	//}

	for (count = 0; count < TWELVE_INTEGERS; count++)
	{
		total += tracks[count];
		average = total / TWELVE_INTEGERS;
	}
	cout << "The average length of a track is: " << average << endl;

	system("pause");
	return 0;
}
Thank you! I just realized someone replied. I finally figured it out after MUCH stress and help from a classmate! I am usually better about keeping track with my post on this forum. I am so sorry!
Topic archived. No new replies allowed.