Advertisement
desislava_topuzakova

05. Club

Feb 18th, 2023
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. double targetSum; //целева печалба
  8. cin >> targetSum;
  9. cin.ignore();
  10.  
  11. //command -> име на коктейл или "Party!"
  12. string command;
  13. getline(cin, command);
  14.  
  15. double earnedMoney = 0; //спечелените пари
  16.  
  17. //повтаряме: въвеждаме команда
  18. //стоп: command == "Party!"
  19. //продължаваме: command != "Party!"
  20.  
  21. while (command != "Party!")
  22. {
  23. //command e име на коктейл -> "Bellini" -> 7 лв
  24. //брой коктейли
  25. int count;
  26. cin >> count;
  27. cin.ignore();
  28.  
  29. //печалба от въведения котейл
  30. double moneyFromCocktails = count * command.length();
  31.  
  32. //отстъпка
  33. if ((count * command.length()) % 2 == 1)
  34. {
  35. moneyFromCocktails = moneyFromCocktails - moneyFromCocktails * 0.25;
  36. //moneyFromCocktails = 0.75 * moneyFromCocktails;
  37. //moneyFromCocktails *= 0.75;
  38. }
  39.  
  40. //добавяме спечелените пари за коктейла към общите
  41. earnedMoney += moneyFromCocktails;
  42.  
  43. //проверка дали не сме достигнали целта -> спираме въвеждането на коктейли
  44. if (earnedMoney >= targetSum)
  45. {
  46. cout << "Target acquired." << endl;
  47. break;
  48. }
  49.  
  50. getline(cin, command);
  51. }
  52.  
  53.  
  54. cout.setf(ios::fixed);
  55. cout.precision(2);
  56.  
  57. if (command == "Party!")
  58. {
  59. cout << "We need " << targetSum - earnedMoney << " leva more." << endl;
  60. }
  61.  
  62. cout << "Club income - " << earnedMoney << " leva." << endl;
  63.  
  64. }
  65.  
  66. //getline -> няма нужда от ignore след него
  67. //cin и след това getline -> имаме нужда от ingore
  68.  
  69.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement