Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- //j'ai utilisé pour definer une valeur alla variable max qui ne changera jamais au cour du code
- #define max 3
- // j'ai bien defini la structure
- struct prodotti {
- char nom_prod[50];
- float prezzo;
- };
- int main()
- {
- char nom_prod_c[10];
- int i, quantity=0, found = 0;
- float costo_T;
- //j'ai bien defini ma variable qui pointe vers la structure avec une dimension fixe
- struct prodotti prodotto[max];
- printf("inserire il nome dei prodotti ed i relativi prezzi separati da spazi\n");
- for (i = 0; i < 3; i++) {
- printf("prodotto %d : ", i + 1);
- scanf("%s %f", &prodotto[i].nom_prod, &prodotto[i].prezzo);
- fflush(stdin);
- }
- while (found==0) {
- printf("entra il nome del prodotto con la quantita ");
- // on utilise %.2f dans la printf e non la scanf
- scanf("%s %d", &nom_prod_c, &quantity);
- for (i = 0; i < max; i++) {
- if ((strcmp(prodotto[i].nom_prod, nom_prod_c)) == 0) {
- costo_T = prodotto[i].prezzo * quantity;
- printf(" il costo totale del prodotto \%s\ e' di %.2f\n", prodotto[i].nom_prod, costo_T);
- found = 1;
- break;
- // 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
- // j'ai retiré le cicle while parce que ce n'est pas utile dans ce code
- }
- }
- if (found == 0)
- printf("prododotto non trovato, pensi ad un altro nome!\n: ");
- }
- printf("\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement