Advertisement
Guest User

Untitled

a guest
Sep 20th, 2022
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.28 KB | Source Code | 0 0
  1. #include <iostream>
  2. #include <array>
  3. #include <format>
  4. #include <string>
  5.  
  6. int main() {
  7.     auto options = std::to_array<std::string>(
  8.         { "ICU Monitor","Get'er Done! Monitor","Gamer's Delight Monitor", "Checkout" });
  9.     auto prices = std::to_array<float>({ 159.99, 179.99, 249.99 });
  10.  
  11.     float total = 0.0;
  12.     for(;;)
  13.     {
  14.         std::cout << std::format("\n{0:>13}\n", "MENU");
  15.         for (size_t n = 0; n < options.size(); ++n)
  16.         {
  17.             std::cout << std::format("{0}. {1}", (n + 1), options[n]);
  18.             if (n < prices.size()) std::cout << " $" << prices[n];
  19.             std::cout << "\n";
  20.         }
  21.         std::cout << std::format("\nEnter the option (1-{}): ", options.size());
  22.        
  23.         int choice;
  24.         std::cin >> choice;
  25.  
  26.         if ((choice > 0) && (choice <= prices.size()))
  27.         {
  28.             std::cout << "Enter Item Quantity: ";
  29.  
  30.             int quantity;
  31.             std::cin >> quantity;
  32.  
  33.             total += quantity * prices[choice - 1];
  34.         }
  35.         else if (choice == options.size()) break;
  36.         else
  37.         {
  38.             std::cout << "Invalid option";
  39.         }
  40.     }
  41.  
  42.     const float tax_rate = 0.065F;
  43.     float sales_tax = total * tax_rate;
  44.     std::cout <<
  45.         std::format(
  46.             "\nTotal Cost of Monitors: ${0:.2f}"
  47.             "\nSales Tax(calculated at {1:.1f} %) : ${2:.2f}"
  48.             "\nBalance Due: ${3:.2f}\n",
  49.             total, (tax_rate * 100.0), sales_tax, (total + sales_tax));
  50.  
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement