Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // prueba.cpp : main project file.
- #include "stdafx.h"
- #include "stdio.h"
- #include "conio.h"
- #include "ctype.h"
- #define N 3
- using namespace System;
- int main(array<System::String ^> ^args)
- {
- char vcat[N],cat;
- int vedad[N],suma,cont;
- for(int i=0;i<N;i++)
- { do{ _flushall();
- printf("Ingrese categoria(A,B,C): ");
- scanf("%c",&vcat[i]);
- vcat[i]=toupper(vcat[i]);
- }while(vcat[i]<'A' || vcat[i]>'C');
- do{ printf("Ingrese edad: ");
- scanf("%d",&vedad[i]);
- }while(vedad[i]<0 || vedad[i]>100);
- }
- do{ _flushall();
- printf("Ingrese categoria(A,B,C) a buscar: ");
- scanf("%c",&cat);
- cat=toupper(cat);
- }while(cat<'A' || cat>'C');
- suma=0;cont=0;
- for(int i=0;i<N;i++)
- if(vcat[i]==cat)
- { suma=suma+vedad[i];
- cont++;
- }
- printf("El promedio de edad es: %.2f",suma*1.0/cont);
- /*suma1=0;cont1=0;
- for(int i=0;i<N;i++)
- switch(vcat[i])
- { case 'A': suma1=suma1+vedad[i];
- cont1++;break;
- case 'B': suma2=suma2+vedad[i];
- cont2++;break;
- case 'C': suma3=suma3+vedad[i];
- cont3++;break;
- }
- */
- _getch();
- return 0;
- }
Add Comment
Please, Sign In to add comment