Advertisement
Spocoman

01. Computer Store

Nov 4th, 2023
890
1
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 1 0
  1. #include <iostream>
  2. #include <string>
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     string command;
  9.     cin >> command;
  10.    
  11.     double totalPrice = 0, price;
  12.  
  13.     while (command != "special" && command != "regular") {
  14.         price = stod(command);
  15.         if (price > 0) {
  16.             totalPrice += price;
  17.         }
  18.         else {
  19.             cout << "Invalid price!\n";
  20.         }
  21.         cin >> command;
  22.     }
  23.  
  24.     if (totalPrice == 0) {
  25.         cout << "Invalid order!\'n";
  26.     }
  27.     else {
  28.         cout << fixed << setprecision(2) <<
  29.             "Congratulations you've just bought a new computer!\n" <<
  30.             "Price without taxes: " << totalPrice << "$\n" <<
  31.             "Taxes: " << totalPrice / 5 << "$\n" <<
  32.             "-----------\n" <<
  33.             "Total price: " << totalPrice * 1.2 * (command == "special" ? 0.9 : 1) << "$\n";
  34.     }
  35.     return 0;
  36. }
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement