Guest User

Untitled

a guest
Nov 22nd, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. typedef enum { crocchette, scatolette, tonno } Cibo;
  4.  
  5. typedef struct {
  6. int id;
  7. int age;
  8. float weight;
  9. Cibo food_type;
  10. } Gatto;
  11.  
  12. Gatto read_gatto() {
  13. Gatto gatto;
  14.  
  15. scanf("%d", &gatto.id);
  16. scanf("%d", &gatto.age);
  17. scanf("%f", &gatto.weight);
  18. scanf("%d", &gatto.food_type);
  19.  
  20. return gatto;
  21. }
  22.  
  23. void print_gatto(Gatto gatto) {
  24. printf("%d ", gatto.id);
  25.  
  26. switch (gatto.food_type) {
  27. case crocchette:
  28. printf("crocchette\n");
  29. break;
  30. case tonno:
  31. printf("tonno\n");
  32. break;
  33. case scatolette:
  34. printf("scatolette\n");
  35. break;
  36. default:
  37. printf("???\n");
  38. }
  39. }
  40.  
  41. int main() {
  42.  
  43. Gatto arr[4];
  44.  
  45. float media_peso = 0.0;
  46.  
  47. for (int i = 0; i < 4; i++) {
  48. arr[i] = read_gatto();
  49.  
  50. media_peso += arr[i].weight;
  51. }
  52.  
  53. media_peso /= 4.0;
  54.  
  55. for (int i = 0; i < 4; i++) {
  56. if (arr[i].age < 4&& media_peso < arr[i].weight) {
  57. print_gatto(arr[i]);
  58. }
  59. }
  60.  
  61. return 0;
  62. }
Add Comment
Please, Sign In to add comment