Advertisement
janac

Discount prices and display total price

Nov 30th, 2021
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.39 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6.  
  7. // Enter any number of prices.
  8. // Discount each one 25%, then sum them and
  9. // add a 10% tax to the total.
  10. // Display the discounted prices and the final total.
  11.  
  12. int main()
  13. {
  14.     vector<float> discounted_prices; // A string that may represent a number.
  15.     float price = 0; // Individual prices.
  16.     float discount_price = 0; // Price after 25% discount.
  17.     float sum_of_discounted_prices = 0; // Sum of discounted prices.
  18.     float final_price = 0; // Final price after 25% discount and 10% tax.
  19.  
  20.     cout << "Enter any number of prices.\n"
  21.         "Enter -1 when done\n";
  22.     cin >> price; // Get the next price.
  23.     while (price != -1) // While there are more prices to enter,
  24.     {
  25.         discount_price = .75 * price; // Discount the price.
  26.         sum_of_discounted_prices += discount_price; // Add it to the sum.
  27.         discounted_prices.push_back(discount_price); // Store the price.
  28.         cin >> price; // Get the next price.
  29.     }
  30.  
  31.     final_price = .9 * sum_of_discounted_prices; // Take 90% of sum.
  32.  
  33.     cout << "\nList of prices after 25% discount.\n";
  34.     for (float saved_price : discounted_prices) // For each price,
  35.     {
  36.         // Display two decimal points.
  37.         cout << fixed << setprecision(2) << saved_price << '\n';
  38.     }
  39.  
  40.     // Display the final price.
  41.     cout << "\nFinal total including 10% tax = " << final_price << '\n';
  42.  
  43.     return 0; // End the program.
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement