Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <string>
- using namespace std;
- struct Banknote
- {
- int OneRub = 0;
- int TwoRub = 0;
- int FiveRub = 0;
- int TenRub = 0;
- int FiftyRub = 0;
- int HundredRub = 0;
- int TwoHundredRub = 0;
- int FiveHundredRub = 0;
- int ThousandRub = 0;
- int TwoThousandRub = 0;
- int FiveThousandRub = 0;
- int Sum = (OneRub + TwoRub + FiveRub + TenRub + FiftyRub + HundredRub + TwoHundredRub + FiveHundredRub + ThousandRub + TwoThousandRub + FiveThousandRub);
- };
- struct Ingredient
- {
- int Cup = 1;
- int Water = 1;
- int Milk = 0;
- int WhippedMilk = 0;
- int IceCream = 0;
- int Chocolate = 0;
- int Sugar = 0;
- int CoffeeIng = 1;
- };
- struct Coffee
- {
- string Name;
- int Price;
- Ingredient Recipe;
- };
- void NewListOfRecipes(); // Объявление и заполнения массива с рецептами.
- Banknote InputOneBanknote(Banknote & Balance); // Приём одной банкноты.
- void InputMoney(Coffee ListOfRecipes[], int CoffeeNum, Banknote & Balance); // Вызов InputBanknote, пока не наберётся нужная сумма.
- Banknote OutputMoneyCheck(Coffee ListOfRecipes[], int CoffeeNum, Banknote & Balance, Banknote Amount, int & check); // Возвращает сдачу, если её можно выдать, и принятые купюры, если нельзя.
- int main()
- {
- Banknote Balance;
- Banknote Amount;
- Banknote Surrender;
- NewListOfRecipes();
- return 0;
- }
- void NewListOfRecipes()
- {
- Coffee ListOfRecipes[7];
- ListOfRecipes[0].Name = "Espresso";
- ListOfRecipes[0].Price = 30;
- ListOfRecipes[1].Name = "Cappuccino";
- ListOfRecipes[1].Price = 35;
- ListOfRecipes[1].Recipe.Milk = 1;
- ListOfRecipes[1].Recipe.WhippedMilk = 1;
- ListOfRecipes[2].Name = "Glasse";
- ListOfRecipes[2].Price = 50;
- ListOfRecipes[2].Recipe.IceCream = 1;
- ListOfRecipes[2].Recipe.Chocolate = 1;
- ListOfRecipes[3].Name = "Ristretto";
- ListOfRecipes[3].Price = 35;
- ListOfRecipes[3].Recipe.CoffeeIng = 2;
- ListOfRecipes[4].Name = "Mocha";
- ListOfRecipes[4].Price = 60;
- ListOfRecipes[4].Recipe.Milk = 1;
- ListOfRecipes[4].Recipe.WhippedMilk = 1;
- ListOfRecipes[4].Recipe.Chocolate = 1;
- ListOfRecipes[5].Name = "Americano";
- ListOfRecipes[5].Price = 25;
- ListOfRecipes[5].Recipe.Water = 2;
- ListOfRecipes[6].Name = "Mochaccino";
- ListOfRecipes[6].Price = 50;
- ListOfRecipes[6].Recipe.Chocolate = 1;
- ListOfRecipes[6].Recipe.Milk = 1;
- Banknote Balance;
- Balance.FiveThousandRub = Balance.FiveThousandRub + 1;
- Balance.TwoThousandRub = Balance.TwoThousandRub + 1;
- Balance.ThousandRub = Balance.ThousandRub + 2;
- Balance.FiveHundredRub = Balance.FiveHundredRub + 2;
- Balance.TwoHundredRub = Balance.TwoHundredRub + 2;
- Balance.HundredRub = Balance.HundredRub + 5;
- Balance.FiftyRub = Balance.FiftyRub + 5;
- Balance.TenRub = Balance.TenRub + 10;
- Balance.FiveRub = Balance.FiveRub + 20;
- Balance.TwoRub = Balance.TwoRub + 30;
- Balance.OneRub = Balance.OneRub + 40;
- Ingredient Precence;
- Precence.Cup = Precence.Cup + 10;
- Precence.Water = Precence.Water + 10;
- Precence.Milk = Precence.Milk + 10;
- Precence.WhippedMilk = Precence.WhippedMilk + 10;
- Precence.IceCream = Precence.IceCream + 10;
- Precence.Chocolate = Precence.Chocolate + 10;
- Precence.Sugar = Precence.Sugar + 10;
- Precence.CoffeeIng = Precence.CoffeeIng + 10;
- }
- Banknote InputOneBanknote(Banknote & Balance)
- {
- Banknote Amount;
- int BankInd;
- int Check = 0;
- cin >> BankInd;
- do
- {
- switch (BankInd)
- {
- Check = 1;
- case 1 :
- {
- Amount.OneRub = Amount.OneRub + 1;
- Balance.OneRub = Balance.OneRub + 1;
- break;
- }
- case 2:
- {
- Amount.TwoRub = Amount.TwoRub + 1;
- Balance.TenRub = Balance.TenRub + 1;
- break;
- }
- case 5:
- {
- Amount.FiveRub = Amount.FiveRub + 1;
- Balance.FiftyRub = Balance.FiftyRub + 1;
- break;
- }
- case 10:
- {
- Amount.TenRub = Amount.TenRub + 1;
- Balance.TenRub = Balance.TenRub + 1;
- break;
- }
- case 50:
- {
- Amount.FiftyRub = Amount.FiftyRub + 1;
- Balance.FiftyRub = Balance.FiftyRub + 1;
- break;
- }
- case 100:
- {
- Amount.HundredRub = Amount.HundredRub + 1;
- Balance.HundredRub = Balance.HundredRub + 1;
- break;
- }
- case 200:
- {
- Amount.TwoHundredRub = Amount.TwoHundredRub + 1;
- Balance.TwoHundredRub = Balance.TwoHundredRub + 1;
- break;
- }
- case 500:
- {
- Amount.FiveHundredRub = Amount.FiveHundredRub + 1;
- Balance.FiveHundredRub = Balance.FiveHundredRub + 1;
- break;
- }
- case 1000:
- {
- Amount.ThousandRub = Amount.ThousandRub + 1;
- Balance.ThousandRub = Balance.ThousandRub + 1;
- break;
- }
- case 2000:
- {
- Amount.TwoThousandRub = Amount.TwoThousandRub + 1;
- Balance.TwoThousandRub = Balance.TwoThousandRub + 1;
- break;
- }
- case 5000:
- {
- Amount.FiveThousandRub = Amount.FiveThousandRub + 1;
- Balance.FiveThousandRub = Balance.FiveThousandRub + 1;
- break;
- }
- default:
- {
- Check = 0;
- break;
- }
- }
- } while (Check = 0);
- return (Amount);
- }
- void InputMoney(Coffee ListOfRecipes[], int CoffeeNum, Banknote & Balance)
- {
- Banknote Amount;
- do
- {
- Amount = InputOneBanknote(Balance);
- } while (Amount.Sum >= ListOfRecipes[CoffeeNum].Price);
- }
- Banknote OutputMoneyCheck(Coffee ListOfRecipes[], int CoffeeNum, Banknote & Balance, Banknote Amount, int & check)
- {
- Banknote Surrender;
- int IAmountSum = Amount.Sum - ListOfRecipes[CoffeeNum].Price;
- if (IAmountSum <= Balance.Sum)
- {
- while (IAmountSum >= 5000 && Balance.FiveThousandRub >= 1)
- {
- Surrender.FiveThousandRub = Surrender.FiveThousandRub + 1;
- IAmountSum = IAmountSum - 5000;
- }
- while (IAmountSum >= 2000 && Balance.TwoThousandRub >= 1)
- {
- Surrender.TwoThousandRub = Surrender.TwoThousandRub + 1;
- IAmountSum = IAmountSum - 2000;
- }
- while (IAmountSum >= 1000 && Balance.ThousandRub >= 1)
- {
- Surrender.ThousandRub = Surrender.ThousandRub + 1;
- IAmountSum = IAmountSum - 1000;
- }
- while (IAmountSum >= 500 && Balance.FiveHundredRub >= 1)
- {
- Surrender.FiveHundredRub = Surrender.FiveHundredRub + 1;
- IAmountSum = IAmountSum - 500;
- }
- while (IAmountSum >= 100 && Balance.HundredRub >= 1)
- {
- Surrender.HundredRub = Surrender.HundredRub + 1;
- IAmountSum = IAmountSum - 100;
- }
- while (IAmountSum >= 50 && Balance.FiftyRub >= 1)
- {
- Surrender.FiftyRub = Surrender.FiftyRub + 1;
- IAmountSum = IAmountSum - 50;
- }
- while (IAmountSum >= 10 && Balance.TenRub >= 1)
- {
- Surrender.TenRub = Surrender.TenRub + 1;
- IAmountSum = IAmountSum - 10;
- }
- while (IAmountSum >= 5 && Balance.FiveRub >= 1)
- {
- Surrender.FiveRub = Surrender.FiftyRub + 1;
- IAmountSum = IAmountSum - 5;
- }
- while (IAmountSum >= 2 && Balance.TwoRub >= 1)
- {
- Surrender.TwoRub = Surrender.TwoRub + 1;
- IAmountSum = IAmountSum - 2;
- }
- while (IAmountSum >= 1 && Balance.OneRub >= 1)
- {
- Surrender.OneRub = Surrender.OneRub + 1;
- IAmountSum = IAmountSum - 1;
- }
- if (IAmountSum = 0)
- {
- check = 1;
- return Surrender;
- }
- else
- {
- // Автомат не может дать сдачу, вместо сдачи возвращаются принятые купюры.
- return Amount;
- }
- }
- else
- {
- // Автомат не может дать сдачу, вместо сдачи возвращаются принятые купюры.
- return Amount;
- }
- }
- void OutputMoney(Banknote Surrender, Banknote & Balance)
- {
- Balance.FiveThousandRub = Balance.FiveThousandRub - Surrender.FiveThousandRub;
- Balance.TwoThousandRub = Balance.TwoThousandRub - Surrender.TwoThousandRub;
- Balance.ThousandRub = Balance.ThousandRub - Surrender.ThousandRub;
- Balance.FiveHundredRub = Balance.FiveHundredRub - Surrender.FiveHundredRub;
- Balance.TwoHundredRub = Balance.TwoHundredRub - Surrender.TwoHundredRub;
- Balance.HundredRub = Balance.HundredRub - Surrender.HundredRub;
- Balance.FiftyRub = Balance.FiftyRub - Surrender.FiftyRub;
- Balance.TenRub = Balance.TenRub - Surrender.TenRub;
- Balance.FiveRub = Balance.FiveRub - Surrender.FiveRub;
- Balance.TwoRub = Balance.TwoRub - Surrender.TwoRub;
- Balance.OneRub = Balance.OneRub - Surrender.OneRub;
- }
- void OutputCoffee(Ingredient Precence, Coffee ListOfRecipes[], int CoffeeNum)
- {
- Precence.Chocolate = Precence.Chocolate - ListOfRecipes[CoffeeNum].Recipe.Chocolate;
- Precence.CoffeeIng = Precence.CoffeeIng - ListOfRecipes[CoffeeNum].Recipe.CoffeeIng;
- Precence.Cup = Precence.Cup - ListOfRecipes[CoffeeNum].Recipe.Cup;
- Precence.IceCream = Precence.IceCream - ListOfRecipes[CoffeeNum].Recipe.IceCream;
- Precence.Milk = Precence.Milk - ListOfRecipes[CoffeeNum].Recipe.Milk;
- Precence.Sugar = Precence.Sugar - ListOfRecipes[CoffeeNum].Recipe.Sugar;
- Precence.Water = Precence.Water - ListOfRecipes[CoffeeNum].Recipe.Water;
- Precence.WhippedMilk = Precence.WhippedMilk - ListOfRecipes[CoffeeNum].Recipe.WhippedMilk;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement