Guest User

Untitled

a guest
Feb 20th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. // prueba.cpp : main project file.
  2. #include "stdafx.h"
  3. #include "stdio.h"
  4. #include "conio.h"
  5. #include "ctype.h"
  6. #define N 3
  7. using namespace System;
  8. int main(array<System::String ^> ^args)
  9. {
  10. char vcat[N],cat;
  11. int vedad[N],suma,cont;
  12. for(int i=0;i<N;i++)
  13. { do{ _flushall();
  14. printf("Ingrese categoria(A,B,C): ");
  15. scanf("%c",&vcat[i]);
  16. vcat[i]=toupper(vcat[i]);
  17. }while(vcat[i]<'A' || vcat[i]>'C');
  18.  
  19. do{ printf("Ingrese edad: ");
  20. scanf("%d",&vedad[i]);
  21. }while(vedad[i]<0 || vedad[i]>100);
  22. }
  23.  
  24. do{ _flushall();
  25. printf("Ingrese categoria(A,B,C) a buscar: ");
  26. scanf("%c",&cat);
  27. cat=toupper(cat);
  28. }while(cat<'A' || cat>'C');
  29. suma=0;cont=0;
  30. for(int i=0;i<N;i++)
  31. if(vcat[i]==cat)
  32. { suma=suma+vedad[i];
  33. cont++;
  34. }
  35. printf("El promedio de edad es: %.2f",suma*1.0/cont);
  36. /*suma1=0;cont1=0;
  37. for(int i=0;i<N;i++)
  38. switch(vcat[i])
  39. { case 'A': suma1=suma1+vedad[i];
  40. cont1++;break;
  41. case 'B': suma2=suma2+vedad[i];
  42. cont2++;break;
  43. case 'C': suma3=suma3+vedad[i];
  44. cont3++;break;
  45. }
  46. */
  47. _getch();
  48. return 0;
  49. }
Add Comment
Please, Sign In to add comment