Advertisement
Jmdnbvs

Untitled

Jan 6th, 2019
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. /* Ejercicio 2: Hacer una estructura llamada alumno, en la cual se tendrán los siguientes
  2. Campos: Nombre, edad, promedio, pedir datos al usuario para 3 alumnos,
  3. comprobar cuál de los 3 tiene el mejor promedio y posteriormente imprimir los datos del alumno.*/
  4.  
  5. #include <iostream>
  6. #include <conio.h>
  7.  
  8. using namespace std;
  9.  
  10. struct alumno{
  11. char nombre[20];
  12. int edad;
  13. float promedio;
  14.  
  15. }alumnos[3];
  16.  
  17. int main(){
  18.  
  19. float mayor=0, menor=999999;
  20. int posM=0,posm=0;
  21.  
  22.  
  23. for(int i=0;i<3;i++){
  24. cout<<"Ingrese el nombre del alumno: ";
  25. cin.getline(alumnos[i].nombre,20,'\n');
  26. cout<<"Ingrese la edad del alumno: ";
  27. cin>>alumnos[i].edad;
  28. cout<<"Ingrese el promedio del alumno: ";
  29. cin>>alumnos[i].promedio;
  30. }
  31.  
  32. if(alumnos[i].promedio>mayor){
  33. mayor= alumnos[i].promedio;
  34. posM= i;
  35. }
  36.  
  37. cout<<"\nDatos del alumno con mayor promedio: "<<endl;
  38. cout<<"Nombre: "<<alumnos[posM].nombre<<endl;
  39. cout<<"Edad: "<<alumnos[posM].edad<<endl;
  40. cout<<"Promedio: "<<alumnos[posM].promedio<<endl;
  41. cout<<"_____________________________________"<<endl;
  42.  
  43. getch();
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement