amlxv

flame

May 22nd, 2022 (edited)
151
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<stdio.h>
  2.  
  3. struct Product
  4. {
  5.     /* data */
  6.     char name; // Product Name
  7.     int p1; // Process 1
  8.     int p2; // Process 2
  9.     float price; // Unit Price
  10. };
  11.  
  12. struct Product Item[];
  13.  
  14. int main() {
  15.     // Product A
  16.     Item[0].name = 'A';
  17.     Item[0].p1 = 10;
  18.     Item[0].p2 = 6;
  19.     Item[0].price = 4.50;
  20.  
  21.     // Product B
  22.     Item[1].name = 'B';
  23.     Item[1].p1 = 5;
  24.     Item[1].p2 = 8;
  25.     Item[1].price = 5.00;
  26.  
  27.     // Product C
  28.     Item[2].name = 'C';
  29.     Item[2].p1 = 6;
  30.     Item[2].p2 = 9;
  31.     Item[2].price = 4.00;
  32.  
  33.  
  34.     // Display all of the products
  35.     printf("Product \t\t\t p1 \t\t  p2 \t\t price \n");
  36.     printf("-----------------------------------------------------\n");
  37.  
  38.     for(int i = 0; i < 3; i++)
  39.     {
  40.         printf("%c \t\t\t %d \t\t\t %d \t\t\t %.2f \n", Item[i].name, Item[i].p1, Item[i].p2, Item[i].price);
  41.     }
  42.  
  43.     /**
  44.      * Calculate and print the total price of the products
  45.      * Modify the produce_unit quantity as if
  46.      *
  47.      */
  48.     int produce_unit[] = {3, 5, 7};
  49.     float total = (Item[0].price * produce_unit[0]) + (Item[1].price * produce_unit[1]) + (Item[2].price * produce_unit[2]);
  50.  
  51.     printf("\n\n# Total Costs of All Products\n");
  52.     printf("Product \t\t\t p1 \t\t  p2 \t\t price \n");
  53.     printf("-----------------------------------------------------\n");
  54.  
  55.     for(int i = 0; i < 3; i++)
  56.     {
  57.         printf("%c \t\t\t %d \t\t\t %d \t\t\t %.2f \n", Item[i].name, (Item[i].p1 * produce_unit[i]), (Item[i].p2 * produce_unit[i]), (Item[i].price * produce_unit[i]));
  58.     }
  59.  
  60.     printf("\nTotal Price: $%.2f", total);
  61.    
  62.     return 0;
  63. }
  64.  
RAW Paste Data Copied