如何在计算最高和最低间隔后在控制台上读取数组编号的下标
How do I get the subscript of an array number to read on the console after calculating highest and lowest intervals?
我正在尝试显示哪个"跟踪"数字被计算为最长和最短。我不确定对这样一个整数的调用是什么。目前我的程序只调用 0,这是我两者的起始值。任何帮助将不胜感激。
这是我正在谈论的代码部分。数组中有 12 个项目。
longest = albumlength[0];
for (count = 1; count < Num_Tracks; count++)
if (albumlength[count] > longest)
longest = albumlength[count];
shortest = albumlength[0];
for (count = 1; count < Num_Tracks; count++)
if (albumlength[count] < shortest)
shortest = albumlength[count];
int total = 0;
int average;
for (int count = 0; count < Num_Tracks; count++)
total += albumlength[count];
average = total / Num_Tracks;
cout << endl;
cout << "The longest track is #" << albumlength[longest] << " at ";
displayTime(longest);
cout << "The shortest track is #" << albumlength[shortest] << " at ";
displayTime(shortest);
cout << "The total length of the album is: ";
displayTime(total);
cout << "The average length of a track is: ";
displayTime(average);
代码正在计算实际的最长和最短值,然后您将该值用作曲目编号的索引。这是没有道理的。
如果您想弄清楚"计算了哪个'轨道'编号",请准确操作:跟踪轨道编号本身,而不是实际的最短或最长值:
longest = 0;
for (count = 1; count < Num_Tracks; count++)
if (albumlength[count] > albumlength[longest])
longest = count;
现在longest
是最长轨道的数量,而不是最长轨道的实际值。对最短的轨道执行相同的操作。
相关文章:
- SSH通过/sbin/SSH无法读取RSA密钥文件(从控制台运行)
- 从文件读取并通过矢量输出到控制台
- 反转从控制台读取的文本
- 控制台未正确读取输入字符串
- 如何读取windows服务启动的控制台应用程序的输出
- 如何使用 cin 将整数从控制台读取到向量中
- 如何从 c++ 控制台读取未知行数(允许空行)上的输入
- 硬编码字符串与强制转换为 PUCHAR 并打印到控制台时从控制台读取的字符串的结果不同
- 如何从控制台启动可执行文件并使用Qt读取输出
- C++ 从控制台读取整数数组
- 从控制台输出读取 C++
- 指向C 中的结构 - 从控制台读取
- 控制台将继续关闭,而不是读取 if 语句中的字符串
- 如何读取控制台输入并将其存储到向量字符串中
- 在Qt控制台应用程序中读取和写入QProcess
- 如何从文件中一次读取一个输入,类似于在c++中使用cin/scanf从控制台读取输入
- 执行带有参数的 .bat 文件并以 C++ 格式读取控制台输出
- 从控制台读取字符
- 使用RInside读取R控制台
- 读取控制台调色板的 RGB 值