Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace CakeTycoon
- {
- using System;
- public class CakeTycoon
- {
- public static void Main(string[] args)
- {
- /* Keep "magic numbers" out of your code by using constants
- * Using a named constant/variable is easier to understand
- */
- const double ProfitMultiplier = 1.25;
- // Be very careful of the types you choose
- ulong cakesWanted = ulong.Parse(Console.ReadLine());
- double flourPerCakeNeeded = double.Parse(Console.ReadLine());
- uint availableFlour = uint.Parse(Console.ReadLine());
- uint trufflesAvailable = uint.Parse(Console.ReadLine());
- uint priceOfTruffle = uint.Parse(Console.ReadLine());
- // How many cakes can we produce with the flour we have?
- ulong maxCakes = (ulong)(availableFlour / flourPerCakeNeeded);
- // Two outcomes depending on whether we can produce as many cakes as we want
- if (maxCakes < cakesWanted)
- {
- /* Calculate how much flour we lack; this is only relevant in this case
- * so keep calculations here, no need to do them before we know if we'll
- * need them */
- double totalFlourNeeded = flourPerCakeNeeded * cakesWanted;
- double flourDeficit = totalFlourNeeded - availableFlour;
- Console.WriteLine(
- "Can make only {0} cakes, need {1:F2} kg more flour",
- maxCakes,
- flourDeficit);
- }
- else
- {
- // Calculate the price of each cake; again, only relevant in this case
- ulong totalTrufflePrice = (ulong)trufflesAvailable * priceOfTruffle;
- double priceOfCake = totalTrufflePrice * ProfitMultiplier / cakesWanted ;
- Console.WriteLine(
- "All products available, price of a cake: {0:F2}",
- priceOfCake);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement