nikolas_serafini

Lista 6 - Exercício 8

Aug 9th, 2013
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.07 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #define MAXNAME 31
  4. #define MAXPEOPLE 80
  5.  
  6. typedef struct human {
  7.     char name[MAXNAME];
  8.     int age;
  9.     float weight;
  10. }individual;
  11.  
  12.  
  13. int main() {
  14.  
  15.     int i,currentsSize = 0,control = 0, teenager[MAXPEOPLE];
  16.     struct human personVector[MAXPEOPLE];
  17.  
  18.     while(1) {
  19.         printf("Entre com o nome do individuo : (tecle 'sair' para parar a insercao)\n");
  20.         fflush(stdin);
  21.         gets(personVector[currentsSize].name);
  22.  
  23.         if (strcmp(personVector[currentsSize].name,"sair") == 0){
  24.             currentsSize--;
  25.             break;
  26.         }
  27.         else {
  28.             printf("Entre com o peso do individuo :\n");
  29.             scanf("%f",&personVector[currentsSize].weight);
  30.             printf("Entre com a idade do individuo :\n");
  31.             scanf("%d",&personVector[currentsSize].age);
  32.             if (personVector[currentsSize].age >= 12 && personVector[currentsSize].age <= 17) {
  33.                 teenager[control] = currentsSize;
  34.                 control++;
  35.             }
  36.             currentsSize++;
  37.         }
  38.     }
  39.  
  40.     printf("Pessoas com idades entre 12 e 17 anos :\n");
  41.     for (i = 0; i < control; i++)
  42.     {
  43.         printf("%s\n",personVector[teenager[i]].name);
  44.     }
  45.  
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment