fork download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. double prices[] = {25.00, 5.50, 200.00, 150.00, 80.00, 30.00};
  5. double totalPrice = 0.0;
  6. char moreItems = 'Y';
  7.  
  8. printf(" Welcome to XYZ Auto Tyres & Services Sdn Bhd\n");
  9. printf("--------------------------------------------------------\n");
  10. printf(" Item for services and spare parts:\n");
  11.  
  12. do {
  13. printf("1. Tyre Alignment - RM %.2f\n", prices[0]);
  14. printf("2. Tyre Balancing - RM %.2f\n", prices[1]);
  15. printf("3. New Tyre - RM %.2f\n", prices[2]);
  16. printf("4. Engine Oil (inclusive) - RM %.2f\n", prices[3]);
  17. printf("5. Engine Tuning - RM %.2f\n", prices[4]);
  18. printf("6. Brake Services - RM %.2f\n", prices[5]);
  19.  
  20. int itemCode;
  21. printf("\nEnter the item code: ");
  22. scanf("%d", &itemCode);
  23.  
  24. if (itemCode < 1 || itemCode > 6) {
  25. printf("Invalid item code\n");
  26. return 1;
  27. }
  28.  
  29. int quantity;
  30. printf("Enter the quantity: ");
  31. scanf("%d", &quantity);
  32.  
  33. totalPrice += prices[itemCode - 1] * quantity;
  34.  
  35. printf("Any more items? (Y/N): ");
  36. scanf("%c", &moreItems);
  37.  
  38. } while (moreItems == 'Y' || moreItems == 'y');
  39.  
  40. printf("Total price: RM %.2f\n", totalPrice);
  41.  
  42. return 0;
  43. }
Success #stdin #stdout 0s 5304KB
stdin
4 
3
Y
2
5
N
stdout
          Welcome to XYZ Auto Tyres & Services Sdn Bhd
--------------------------------------------------------
         Item for services and spare parts:
1. Tyre Alignment           - RM 25.00
2. Tyre Balancing           - RM 5.50
3. New Tyre                 - RM 200.00
4. Engine Oil (inclusive)   - RM 150.00
5. Engine Tuning            - RM 80.00
6. Brake Services           - RM 30.00

Enter the item code: Enter the quantity: Any more items? (Y/N): Total price: RM 450.00