【发布时间】:2020-07-09 17:41:42
【问题描述】:
我正在尝试在包含年龄数字的数组中找到最高的项目。 问题是它会在 if 行返回随机数。我想弄明白它背后的逻辑。
语言是 C++,我很确定这很容易解决。
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int edad[100], n, i, emayor=0;
float suma;
do {
cout << "Ingrese su edad: ";
cin >> edad[i];
suma+=edad[i];
i++;
cout << "\n\nDesea Ingresar Edades? (1/0) ";
cin >> n;
} while(n==1 && i<100);
cout << "La sumatoria de edades es: "<< suma;
if (edad[i]>emayor) {
emayor=edad[i];
cout << "\nLa edad mayor es: "<<emayor;
}
getch();
return 0;
}
【问题讨论】:
-
i在那一行上有什么值?