desislava_topuzakova

05. Club

Feb 20th, 2021
786
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.48 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <math.h>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     double needSum;
  9.     cin >> needSum;
  10.     cin.ignore();
  11.     double earnedMoney = 0;
  12.     //команда -> име на коктейл или парти
  13.     //stop -> команда е "Party!"
  14.     //продължаваме -> команда != "Party!"
  15.     string command;
  16.     getline(cin, command);
  17.  
  18.     while (command != "Party!") {
  19.         //коктейл
  20.         string cocktail = command;
  21.         int count;
  22.         cin >> count;
  23.         cin.ignore();
  24.         //печалбата от коктейла = цена на коктейла * броя на коктейлите -> добавим към спечелените пари
  25.         int moneyForCocktails = count * cocktail.length();
  26.  
  27.         if (moneyForCocktails % 2 == 1) {
  28.             double finalPriceOrder = moneyForCocktails - 0.25 * moneyForCocktails; //0.75 * moneyForCocktails
  29.             earnedMoney += finalPriceOrder;
  30.         }
  31.         else {
  32.             earnedMoney += moneyForCocktails;
  33.         }
  34.        
  35.  
  36.         if (earnedMoney >= needSum) {
  37.             cout << "Target acquired." << endl;
  38.             break;
  39.         }
  40.  
  41.         getline(cin, command);
  42.     }
  43.  
  44.     cout.setf(ios::fixed);
  45.     cout.precision(2);
  46.     if (command == "Party!") {
  47.         cout << "We need " << needSum - earnedMoney << " leva more." << endl;
  48.     }
  49.     cout << "Club income - " << earnedMoney << " leva." << endl;
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment