Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main()
- {
- double targetSum; //целева печалба
- cin >> targetSum;
- cin.ignore();
- //command -> име на коктейл или "Party!"
- string command;
- getline(cin, command);
- double earnedMoney = 0; //спечелените пари
- //повтаряме: въвеждаме команда
- //стоп: command == "Party!"
- //продължаваме: command != "Party!"
- while (command != "Party!")
- {
- //command e име на коктейл -> "Bellini" -> 7 лв
- //брой коктейли
- int count;
- cin >> count;
- cin.ignore();
- //печалба от въведения котейл
- double moneyFromCocktails = count * command.length();
- //отстъпка
- if ((count * command.length()) % 2 == 1)
- {
- moneyFromCocktails = moneyFromCocktails - moneyFromCocktails * 0.25;
- //moneyFromCocktails = 0.75 * moneyFromCocktails;
- //moneyFromCocktails *= 0.75;
- }
- //добавяме спечелените пари за коктейла към общите
- earnedMoney += moneyFromCocktails;
- //проверка дали не сме достигнали целта -> спираме въвеждането на коктейли
- if (earnedMoney >= targetSum)
- {
- cout << "Target acquired." << endl;
- break;
- }
- getline(cin, command);
- }
- cout.setf(ios::fixed);
- cout.precision(2);
- if (command == "Party!")
- {
- cout << "We need " << targetSum - earnedMoney << " leva more." << endl;
- }
- cout << "Club income - " << earnedMoney << " leva." << endl;
- }
- //getline -> няма нужда от ignore след него
- //cin и след това getline -> имаме нужда от ingore
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement