Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- struct Product
- {
- /* data */
- char name; // Product Name
- int p1; // Process 1
- int p2; // Process 2
- float price; // Unit Price
- };
- struct Product Item[];
- int main() {
- // Product A
- Item[0].name = 'A';
- Item[0].p1 = 10;
- Item[0].p2 = 6;
- Item[0].price = 4.50;
- // Product B
- Item[1].name = 'B';
- Item[1].p1 = 5;
- Item[1].p2 = 8;
- Item[1].price = 5.00;
- // Product C
- Item[2].name = 'C';
- Item[2].p1 = 6;
- Item[2].p2 = 9;
- Item[2].price = 4.00;
- // Display all of the products
- printf("Product \t\t\t p1 \t\t p2 \t\t price \n");
- printf("-----------------------------------------------------\n");
- for(int i = 0; i < 3; i++)
- {
- 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);
- }
- /**
- * Calculate and print the total price of the products
- * Modify the produce_unit quantity as if
- *
- */
- int produce_unit[] = {3, 5, 7};
- float total = (Item[0].price * produce_unit[0]) + (Item[1].price * produce_unit[1]) + (Item[2].price * produce_unit[2]);
- printf("\n\n# Total Costs of All Products\n");
- printf("Product \t\t\t p1 \t\t p2 \t\t price \n");
- printf("-----------------------------------------------------\n");
- for(int i = 0; i < 3; i++)
- {
- 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]));
- }
- printf("\nTotal Price: $%.2f", total);
- return 0;
- }
Add Comment
Please, Sign In to add comment