C++:输出问题
C++: Issue with output
我有一个C++程序的以下代码,设计用于执行以下操作:开发并运行一个程序,该程序有两个函数,分别在数组中查找最大值(称为findLargest)和在数组中寻找最小值(称之为findSmallest)。代码编译没有问题,但输出没有正确显示,我得到了一系列重复的数字,上面写着"-9.25596e+61"。如果有人能帮我解决这个问题,我将不胜感激。非常感谢。
#include <iostream>
using namespace std;
double findLargest(const double LIST[], int);
double findSmallest(const double LIST[], int);
void printArray(const double LIST[], int);
int main()
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
const int MAX = 10;
double list[MAX] = { 32, 54, 67.5, 29, -34.5, 80, 115, 44.5, 100, 65 }; // elements for the array
printArray(list, MAX);
cout << "nnThe largest number is: " << findLargest(list, MAX);
cout << "nnThe smallest number is: " << findSmallest(list, MAX) << "nn";
system("pause");
return 0;
}
double findLargest(const double LIST[], int size) //function to evaluate the largest elements and output it out
{
double largest = LIST[0];
for (int a = 0; a < size; a++)
{
if (LIST[a] > largest)
{
largest = LIST[a];
}
}
return largest;
}
double findSmallest(const double LIST[], int size) // function to evaluate the smallest and output it out
{
double smallest = LIST[0];
for (int a = 0; a < size; a++)
{
if (LIST[a] < smallest)
{
smallest = LIST[a];
}
}
return smallest;
}
void printArray(const double LIST[], int size) // function to print array
{
cout << "nnThe size of the element is: " << size << "nn";
for (int a = 0; a < size; a++)
{
cout << setw(9) << LIST[a];
if ((a + 1) % 8 == 0)
cout << endl;
}
}
据我所见,您的问题是需要包含以下文件:
<iomanip>
添加行:
#include <iomanip>
到代码的开头,看看这是否有帮助。
相关文章:
- 可能我知道为什么这段代码没有给出任何输出吗?
- 有没有办法我可以在 C++ 中使用 if 语句来说明如果一个字符串不是两个名称的 eqal,它会给出一个输出,ATM i
- 为什么带有逻辑和运算符以及增量运算符的 c++ 程序给出的输出与预期不同?
- C++向量排序给出0作为输出
- 奇怪的数字随机出现在输出中.(C++)
- 如何从Visual Studio中的给出.pyd输出中构造Python代码
- 我将 c++ 矢量数据集转换为 c 数组.我将相同的数据集传递到一个应该给出相同输出的函数中
- 向量<对<双精度,双精度>>给出问题
- 为什么这段代码给出的输出与预期不同?
- C 反向一个不给出预期输出的数组
- 矢量在超出边界时给出0作为输出
- 我很确定我犯了一个愚蠢的错误,但是这段代码给出的输出太长而无法阅读
- C++ 中的侵蚀函数不给出任何输出
- 为什么字符串变量"sum"不存储任何数据,程序不给出任何输出
- 输入层类型:图像数据在窗口咖啡cpp中给出空白输出
- 在队列中,插入和删除后,被删除的元素也会出现在输出中.为什么
- 服务器未收到UDP数据包,花费数小时试图找出问题所在
- 程序给出 0 作为输出 (C++)
- C++ 输出找出问题
- 在成功运行10小时后,在发布模式下从windows应用程序中获得异常,如何检测出问题