gpt4 book ai didi

c++ - 获得垃圾值

转载 作者:行者123 更新时间:2023-11-28 08:21:54 24 4
gpt4 key购买 nike

这是我的代码示例。我正在获取最大高度的值。但我的最低高度是垃圾值。我做错了什么

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
#include <sstream>
using namespace std;

#define MAX 20

struct DATA
{
int id;
string name;
float height;
}numarray[MAX];

int main()
{
int num = 0;
numarray[num].height = fstr3;// contains float values from a file

float minimum, maximum;
minimum = numarray[0].height;
maximum = numarray[0].height;
for(int i = 0; i < MAX; i++)
{
{
if(numarray[i].height < minimum)
{
minimum = numarray[i].height;
}
else if(numarray[i].height > maximum)
{
maximum = numarray[i].height;
}
}
cout<< minimum<< " " << maximum<< endl;
return 0;
}
}

最佳答案

垃圾进,垃圾出。看起来您的输入例程(您没有发布)可能未正确填充数据。我会查看调试器中的输入数据(即使您选择的调试器是 printf())。

关于c++ - 获得垃圾值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5524439/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com