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.
#include <iostream>;
#include <iomanip>; //will be used later in a function
usingnamespace std;
int main()
{
constint 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
longdouble 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;
}
#include <iostream>;
#include <iomanip>; //will be used later in a function
usingnamespace std;
int main()
{
constint 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
longdouble 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!