Advertisement
pcwizz

sweetshop

Jul 30th, 2014
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.94 KB | None | 0 0
  1. using System;
  2.  
  3. namespace KidInACandyStore
  4. {
  5.     struct kidCandyShop {//slightly overkill
  6.         public decimal price,
  7.             money;
  8.     }
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             InitConsole();
  14.             kidCandyShop myKidCandyShop;
  15.             myKidCandyShop.price = GetDecimal("Enter the unit price of a bag in decimal.");
  16.             myKidCandyShop.money = GetDecimal("Enter the monitary funds you have available in Decimal.");
  17.             Console.BackgroundColor = ConsoleColor.DarkYellow;
  18.             Console.WriteLine("If the price is £{0} and you have £{1}.\nYou can purchase {2} bags of jelly BEENZ.",
  19.                 myKidCandyShop.price,
  20.                 myKidCandyShop.money,
  21.                 NumberOfBags(ref myKidCandyShop));
  22.             Console.BackgroundColor = ConsoleColor.Green;
  23.             Console.WriteLine("You will have £{0} left over.", LeftOverMoney(ref myKidCandyShop));
  24.             Console.ReadKey();
  25.         }
  26.  
  27.         //Worker functions
  28.         static int NumberOfBags(ref kidCandyShop myKidCandyShop) {//1 bag is the min unit
  29.             return Convert.ToInt32(myKidCandyShop.money / myKidCandyShop.price);
  30.         }
  31.         //Deprocated in favour of decimal
  32.         //static int GetInteger(string message) {
  33.         //    Console.WriteLine(message);
  34.         //    return Convert.ToInt32(Console.ReadLine());
  35.         //}
  36.         static decimal GetDecimal(string message)
  37.         {
  38.             Console.WriteLine(message);
  39.             return Convert.ToDecimal(Console.ReadLine());
  40.         }
  41.         static decimal LeftOverMoney(ref kidCandyShop myKidCandyShop) {
  42.             return myKidCandyShop.money % myKidCandyShop.price;
  43.         }
  44.  
  45.         static void InitConsole() {//slightly overkill
  46.             Console.Clear();
  47.             Console.BackgroundColor = ConsoleColor.White;
  48.             Console.ForegroundColor = ConsoleColor.Black;
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement