Advertisement
Derik_hacker

Untitled

Feb 9th, 2024
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.78 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. //j'ai utilisé pour definer une valeur alla variable max qui ne changera jamais au cour du code
  6. #define max 3
  7. // j'ai bien defini la structure
  8. struct prodotti {
  9.     char nom_prod[50];
  10.     float prezzo;
  11. };
  12.  
  13. int main()
  14. {
  15.     char nom_prod_c[10];
  16.     int i, quantity=0, found = 0;
  17.     float costo_T;
  18.     //j'ai bien defini ma variable qui pointe vers la  structure avec une dimension fixe
  19.     struct prodotti prodotto[max];
  20.  
  21.  
  22.  
  23.    
  24.     printf("inserire  il nome dei prodotti ed i relativi prezzi separati da spazi\n");
  25.     for (i = 0; i < 3; i++) {
  26.         printf("prodotto %d : ", i + 1);
  27.         scanf("%s %f", &prodotto[i].nom_prod, &prodotto[i].prezzo);
  28.         fflush(stdin);
  29.     }
  30.  
  31.       while (found==0)  {
  32.  
  33.           printf("entra il nome del prodotto con la quantita ");
  34.  
  35.           // on utilise %.2f dans la printf e non la scanf
  36.           scanf("%s %d", &nom_prod_c, &quantity);
  37.         for (i = 0; i < max; i++) {
  38.             if ((strcmp(prodotto[i].nom_prod, nom_prod_c)) == 0) {
  39.                 costo_T = prodotto[i].prezzo * quantity;
  40.                 printf(" il costo totale del prodotto \%s\ e' di  %.2f\n", prodotto[i].nom_prod, costo_T);
  41.                 found = 1;
  42.                 break;
  43.                 // tu avais mis le found en dessous du break chose qui n'est pas bien ,le break sort du cicle en le mettant apres le break  la valeur de ton foun ne changera jamais
  44.                 // j'ai retiré le cicle while parce que ce n'est pas utile dans ce code
  45.                
  46.                
  47.             }
  48.         }
  49.         if (found == 0)
  50.             printf("prododotto non trovato, pensi ad un altro nome!\n: ");
  51.       }
  52.  
  53.     printf("\n");
  54.     return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement