Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace KidInACandyStore
- {
- struct kidCandyShop {//slightly overkill
- public decimal price,
- money;
- }
- class Program
- {
- static void Main(string[] args)
- {
- InitConsole();
- kidCandyShop myKidCandyShop;
- myKidCandyShop.price = GetDecimal("Enter the unit price of a bag in decimal.");
- myKidCandyShop.money = GetDecimal("Enter the monitary funds you have available in Decimal.");
- Console.BackgroundColor = ConsoleColor.DarkYellow;
- Console.WriteLine("If the price is £{0} and you have £{1}.\nYou can purchase {2} bags of jelly BEENZ.",
- myKidCandyShop.price,
- myKidCandyShop.money,
- NumberOfBags(ref myKidCandyShop));
- Console.BackgroundColor = ConsoleColor.Green;
- Console.WriteLine("You will have £{0} left over.", LeftOverMoney(ref myKidCandyShop));
- Console.ReadKey();
- }
- //Worker functions
- static int NumberOfBags(ref kidCandyShop myKidCandyShop) {//1 bag is the min unit
- return Convert.ToInt32(myKidCandyShop.money / myKidCandyShop.price);
- }
- //Deprocated in favour of decimal
- //static int GetInteger(string message) {
- // Console.WriteLine(message);
- // return Convert.ToInt32(Console.ReadLine());
- //}
- static decimal GetDecimal(string message)
- {
- Console.WriteLine(message);
- return Convert.ToDecimal(Console.ReadLine());
- }
- static decimal LeftOverMoney(ref kidCandyShop myKidCandyShop) {
- return myKidCandyShop.money % myKidCandyShop.price;
- }
- static void InitConsole() {//slightly overkill
- Console.Clear();
- Console.BackgroundColor = ConsoleColor.White;
- Console.ForegroundColor = ConsoleColor.Black;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement