Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Automat
- {
- class Program
- {
- public static float givingChange(float priceOfPotion, float userMoney)
- {
- float rest = 0;
- rest = userMoney - priceOfPotion;
- return rest;
- }
- static void Main()
- {
- Fanta newFanta = new Fanta();
- CocaCola newCocaCola = new CocaCola();
- Sprite newSprite = new Sprite();
- while (true)
- {
- Console.WriteLine("Witaj! Wybierz napój, który chcesz kupić!");
- Console.WriteLine("Wcisnij 1 jeśli ma być to Fanta.");
- Console.WriteLine("Wcisnij 2 jeśli ma być to CocaCola.");
- Console.WriteLine("Wciśnij 3 jeśli ma być to Sprite.");
- Console.WriteLine("Wciśnij 4, by zakończyć!");
- int choice = int.Parse(Console.ReadLine());
- Console.WriteLine();
- while (true)
- {
- if (choice == 1)
- {
- Console.Write("Wybrano Fantę. Wrzuć monetę: ");
- float userMoney = float.Parse(Console.ReadLine());
- Console.WriteLine("Wrzucono: " + userMoney + ".");
- Console.WriteLine();
- if (newFanta.CountOfPotion > 0)
- {
- if (userMoney >= newFanta.Price)
- {
- Console.WriteLine("Odbierz produkt!");
- newFanta.CountOfPotion -= 1;
- Console.WriteLine();
- if (userMoney > newFanta.Price)
- {
- Console.WriteLine("Reszta to: "+givingChange(newFanta.Price, userMoney)+"zł.");
- Console.WriteLine();
- break;
- }
- else
- {
- break;
- }
- }
- else
- {
- Console.WriteLine("Wrzucono za mało pieniędzy!");
- Console.WriteLine();
- break;
- }
- }
- else
- {
- Console.WriteLine("Brak produktu.");
- Console.WriteLine("Wydaje reszte: "+givingChange(newFanta.Price, userMoney)+"zł.");
- Console.WriteLine();
- break;
- }
- }
- else if (choice == 2)
- {
- Console.Write("Wybrano CocaCole. Wrzuć monetę: ");
- float userMoney = float.Parse(Console.ReadLine());
- Console.WriteLine("Wrzucono: " + userMoney + ".");
- Console.WriteLine();
- if (newCocaCola.CountOfPotion > 0)
- {
- if (userMoney >= newCocaCola.Price)
- {
- Console.WriteLine("Odbierz produkt!");
- newCocaCola.CountOfPotion -= 1;
- Console.WriteLine();
- if (userMoney > newCocaCola.Price)
- {
- Console.WriteLine("Reszta to: "+givingChange(newCocaCola.Price, userMoney)+"zł.");
- Console.WriteLine();
- break;
- }
- else
- {
- break;
- }
- }
- else
- {
- Console.WriteLine("Wrzucono za mało pieniędzy!");
- Console.WriteLine();
- break;
- }
- }
- else
- {
- Console.WriteLine("Brak produktu.");
- Console.WriteLine("Wydaje reszte: "+givingChange(newSprite.Price, userMoney)+"zł.");
- Console.WriteLine();
- break;
- }
- }
- else if (choice == 3)
- {
- Console.Write("Wybrano Sprite. Wrzuć monetę: ");
- float userMoney = float.Parse(Console.ReadLine());
- Console.WriteLine("Wrzucono: " + userMoney + ".");
- Console.WriteLine();
- if (newSprite.CountOfPotion > 0)
- {
- if (userMoney >= newSprite.Price)
- {
- Console.WriteLine("Odbierz produkt!");
- newSprite.CountOfPotion -= 1;
- Console.WriteLine();
- if (userMoney > newSprite.Price)
- {
- Console.WriteLine("Reszta to: "+givingChange(newSprite.Price, userMoney)+"zł.");
- Console.WriteLine();
- break;
- }
- else
- {
- break;
- }
- }
- else
- {
- Console.WriteLine("Wrzucono za mało pieniędzy!");
- Console.WriteLine();
- break;
- }
- }
- else
- {
- Console.WriteLine("Brak produktu.");
- Console.WriteLine("Wydaje reszte: "+givingChange(newSprite.Price, userMoney)+"zł.");
- Console.WriteLine();
- break;
- }
- }
- else if (choice == 4)
- {
- System.Environment.Exit(1);
- }
- else
- {
- Console.WriteLine("Nie ma takiego wyboru.");
- Console.WriteLine();
- break;
- }
- }
- }
- }
- }
- class Fanta
- {
- int countOfPotion;
- public int CountOfPotion
- {
- get { return countOfPotion; }
- set { countOfPotion = value; }
- }
- float price;
- public float Price
- {
- get { return price; }
- set { price = value; }
- }
- public Fanta()
- {
- countOfPotion = 3;
- price = 3.0f;
- }
- }
- class CocaCola
- {
- int countOfPotion;
- public int CountOfPotion
- {
- get { return countOfPotion; }
- set { countOfPotion = value; }
- }
- float price;
- public float Price
- {
- get { return price; }
- set { price = value; }
- }
- public CocaCola()
- {
- countOfPotion = 3;
- price = 2.50f;
- }
- }
- class Sprite
- {
- int countOfPotion;
- public int CountOfPotion
- {
- get { return countOfPotion; }
- set { countOfPotion = value; }
- }
- float price;
- public float Price
- {
- get { return price; }
- set { price = value; }
- }
- public Sprite()
- {
- countOfPotion = 3;
- price = 3.50f;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement