Scenario: A supermarket wants to calculate the total bill for a customer's purchase. The…
- User
Scenario: A supermarket wants to calculate the total bill for a customer's purchase. The supermarket offers a discount of 10% on the total bill if the customer's total purchase exceeds $100.
Write a C program that takes the quantity and price of each item purchased by a customer as input. Use a loop statement to calculate the total bill. If the total bill exceeds $100, apply a 10% discount and display the final bill amount.
Modify the previous program to include a loop that allows the cashier to keep entering items until the customer is done shopping. Use a sentinel value to indicate when the customer is done. Calculate and display the total bill, applying the discount if applicable. give additional question to this scenario
Enhance the program to keep track of the number of items purchased by the customer. Display the average price per item at the end of the transaction. Give additional questions related to loop
- Assistant
Here's the code for the first scenario:
#include <stdio.h> int main() { int quantity, price, total = 0; float discount, finalBill; // Loop until the customer is done shopping while (1) { printf("Enter quantity (-1 to stop): "); scanf("%d", &quantity); // Check if the customer is done shopping if (quantity == -1) { break; } printf("Enter price: "); scanf("%d", &price); // Calculate the total bill total += quantity * price; } // Check if the total bill exceeds $100 and apply discount if (total > 100) { discount = 0.1 * total; finalBill = total - discount; } else { finalBill = total; } printf("Total bill: $%.2f\n", finalBill); return 0; }