Advertisement
EBobkunov

cookbook

Mar 10th, 2023
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.09 KB | Source Code | 0 0
  1. #include <stdio.h>
  2.  
  3. struct ingredients{
  4.     int ingrs;
  5.     int quantity;
  6.     char iname[20][20];
  7. };
  8.  
  9. struct recipes{
  10.     char name[50];
  11.     struct ingredients I;
  12. };
  13.  
  14. struct cookbook{
  15.     struct recipes R;
  16. };
  17.  
  18. int main() {
  19.     int n;
  20.     printf("Enter number of recipes: \n");
  21.     scanf("%d", &n);
  22.     struct cookbook C[n];
  23.     for(int i = 0; i < n; i++){
  24.         printf("Enter name of recipe: \n");
  25.         scanf("%s", C[i].R.name);
  26.         printf("Enter number of ingredients: (From 2 to 10) \n");
  27.         scanf("%d", &C[i].R.I.ingrs);
  28.         for (int j = 0; j < C[i].R.I.ingrs; j++){
  29.             printf("Enter name of ingredient: \n");
  30.             scanf("%s", C[i].R.I.iname); //[j]
  31.             printf("Enter quantity of ingredient: \n");
  32.             scanf("%d", &C[j].R.I.quantity);
  33.         }
  34.     }
  35.     for(int i = 0; i < n; i++){
  36.         printf("Recipe: %s\n", C[i].R.name);
  37.         for (int j = 0; j < C[i].R.I.ingrs; j++){
  38.             printf("Ingredient: %s, quantity: %d \n", C[j].R.I.iname, C[j].R.I.quantity);
  39.         }
  40.         printf("\n");
  41.     }
  42.     return 0;
  43. }
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement