Delta_Sierra

revise-code_ramirez-AS54

Nov 29th, 2025
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.74 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main() {
  5.     char username[30];
  6.     char discountpicked;
  7.  
  8.     int quantity[4] = {0};
  9.     int itemSummary[4] = {0, 0, 0, 0};
  10.     float prices[4] = {950.00, 399.00, 250.50, 89.50};
  11.  
  12.     float change = 0, cash = 0;
  13.     float subtotal = 0, total = 0;
  14.     float discount = 0, VATamount = 0;
  15.  
  16.     float totalEarnings = 0;
  17.     int totalOrders = 0;
  18.     int choice = 0;
  19.     int exitChoice = 0;
  20.  
  21.     printf("You are currently logged out.\n");
  22.     printf("Enter Username: ");
  23.     scanf("%29s", username);
  24.  
  25.     while (strcmp(username, "Admin") != 0) {
  26.         printf("Wrong username! Try Again.\n");
  27.         printf("Enter username: ");
  28.         scanf("%29s", username);
  29.     }
  30.  
  31.     printf("\n===== CS 101 CASHIER SIMULATOR =====\n\n");
  32.     do {
  33.         subtotal = 0;
  34.         discount = 0;
  35.         VATamount = 0;
  36.         total = 0;
  37.         cash = 0;
  38.         change = 0;
  39.         int currentTransItems = 0;
  40.        
  41.         for (int i = 0; i < 4; i++) quantity[i] = 0;
  42.  
  43.         printf("\n--- New Order ---\n");
  44.         for (int i = 0; i < 4; i++) {
  45.             printf("Item %d -> ", i + 1);
  46.  
  47.             while (scanf("%d", &quantity[i]) != 1) {
  48.                 printf("Invalid input! Numbers only.\n");
  49.                 scanf("%*s");
  50.                 printf("Item %d -> ", i + 1);
  51.             }
  52.             currentTransItems += quantity[i];
  53.         }
  54.  
  55.         if (currentTransItems == 0) {
  56.             printf("No items purchased. Transaction cancelled.\n");
  57.             goto ASK_CHOICE;
  58.         }
  59.         do {
  60.             printf("Is Customer Senior/PWD? Y/N: ");
  61.             scanf(" %c", &discountpicked);
  62.  
  63.             if (discountpicked != 'Y' && discountpicked != 'y' &&
  64.                 discountpicked != 'N' && discountpicked != 'n') {
  65.                 printf("Invalid input! Please enter Y or N.\n\n");
  66.             }
  67.         } while (discountpicked != 'Y' && discountpicked != 'y' &&
  68.                  discountpicked != 'N' && discountpicked != 'n');
  69.         for (int i = 0; i < 4; i++) {
  70.             subtotal += prices[i] * quantity[i];
  71.             itemSummary[i] += quantity[i];
  72.         }
  73.  
  74.         if (discountpicked == 'Y' || discountpicked == 'y') {
  75.             discount = subtotal * 0.12;
  76.             VATamount = 0;
  77.             total = subtotal - discount;
  78.         } else {
  79.             discount = 0;
  80.             VATamount = subtotal - (subtotal / 1.12);
  81.             total = subtotal;
  82.         }
  83.  
  84.         printf("Total to pay: %.2f\n", total);
  85.         do {
  86.             printf("Customer gave: ");
  87.             scanf("%f", &cash);
  88.            
  89.             if(cash < total) {
  90.                 printf("Insufficient cash! You need at least %.2f. Try again.\n", total);
  91.             }
  92.         } while (cash < total);
  93.  
  94.         change = cash - total;
  95.         totalEarnings += total;
  96.         totalOrders++;
  97.  
  98.         printf("\n======== RECEIPT ========\n");
  99.         printf("EMTC1CT Business\n");
  100.         printf("Lozol Taft Avenue.\n");
  101.         printf("Cashier: %s\n\n", username);
  102.  
  103.         for (int i = 0; i < 4; i++) {
  104.             if (quantity[i] > 0)
  105.                 printf("Item %d x %d = %.2f\n", i + 1, quantity[i], prices[i] * quantity[i]);
  106.         }
  107.  
  108.         printf("\nSubtotal:         %.2f\n", subtotal);
  109.         printf("Senior/PWD disc: -%.2f\n", discount);
  110.         printf("VAT amount:       %.2f\n", VATamount);
  111.         printf("-------------------------\n");
  112.         printf("Items Purchased:  %d\n", currentTransItems);
  113.         printf("Total:            %.2f\n", total);
  114.         printf("Cash:             %.2f\n", cash);
  115.         printf("Change:           %.2f\n", change);
  116.         printf("=========================\n");
  117.  
  118.         ASK_CHOICE:
  119.         printf("\n1 - Another transaction\n");
  120.         printf("2 - Logout / End Shift\n");
  121.         printf("Enter choice: ");
  122.         scanf("%d", &choice);
  123.         printf("=========================\n");
  124.  
  125.     } while (choice == 1);
  126.  
  127.     printf("\nClosing cash register manned by %s\n", username);
  128.     printf("Total orders processed: %d\n", totalOrders);
  129.  
  130.     int grandTotalItems = itemSummary[0] + itemSummary[1] + itemSummary[2] + itemSummary[3];
  131.     printf("Total items sold: %d\n", grandTotalItems);
  132.  
  133.     printf("Breakdown of items sold:\n");
  134.     for (int i = 0; i < 4; i++) {
  135.         printf("Item %d: %d pcs\n", i + 1, itemSummary[i]);
  136.     }
  137.  
  138.     printf("Total earnings: %.2f\n", totalEarnings);
  139.     printf("===============================\n");
  140.  
  141.     printf("1 - Login Again\n");
  142.     printf("2 - Exit Program\n");
  143.     printf("Enter choice: ");
  144.     scanf("%d", &exitChoice);
  145.  
  146.     if (exitChoice == 1) {
  147.         printf("\nRestart program to login again.\n");
  148.     } else {
  149.         printf("Program exiting.\n");
  150.     }
  151.  
  152.     return 0;
  153. }
Advertisement
Add Comment
Please, Sign In to add comment