So im having this problem where im trying to get the older age of a quantity of ages. The thing is it would return random numbers at the if line. i want to know the logic behind it.
The language is C++ and im pretty sure this is very easy to solve.
#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;
}
Aucun commentaire:
Enregistrer un commentaire