Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- typedef enum { crocchette, scatolette, tonno } Cibo;
- typedef struct {
- int id;
- int age;
- float weight;
- Cibo food_type;
- } Gatto;
- Gatto read_gatto() {
- Gatto gatto;
- scanf("%d", &gatto.id);
- scanf("%d", &gatto.age);
- scanf("%f", &gatto.weight);
- scanf("%d", &gatto.food_type);
- return gatto;
- }
- void print_gatto(Gatto gatto) {
- printf("%d ", gatto.id);
- switch (gatto.food_type) {
- case crocchette:
- printf("crocchette\n");
- break;
- case tonno:
- printf("tonno\n");
- break;
- case scatolette:
- printf("scatolette\n");
- break;
- default:
- printf("???\n");
- }
- }
- int main() {
- Gatto arr[4];
- float media_peso = 0.0;
- for (int i = 0; i < 4; i++) {
- arr[i] = read_gatto();
- media_peso += arr[i].weight;
- }
- media_peso /= 4.0;
- for (int i = 0; i < 4; i++) {
- if (arr[i].age < 4&& media_peso < arr[i].weight) {
- print_gatto(arr[i]);
- }
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment