Weekly Challenge #1 – Coffee Conundrums – Solutions

A very maths-y challenge to start the year off!

Note: This contains answers to the Coffee Conundrums challenge. Have a go at the challenge before coming here!

Bronze

Console.Write("How many cups of coffee would you like? ");
int numCups = Convert.ToInt32(Console.ReadLine());

const double COST_DIEGO = 1.4;
double totalDiego = numCups * COST_DIEGO;

Console.WriteLine("Total Cost: £{0}", totalDiego);
numCups = int(input("How many cups of coffee would you like? "))

COST_DIEGO = 1.4
totalDiego = numCups * COST_DIEGO

print("Total Cost: £" + str(totalDiego))

Silver

Console.Write("How many cups of coffee would you like? ");
int numCups = Convert.ToInt32(Console.ReadLine());

const double COST_DIEGO = 1.4;
const int LOYALTY_DIEGO = 7;
double totalDiego = COST_DIEGO * (numCups - numCups / LOYALTY_DIEGO);

Console.WriteLine("Total Cost: £{0}", totalDiego);
numCups = int(input("How many cups of coffee would you like? "))

COST_DIEGO = 1.4
LOYALTY_DIEGO = 7
totalDiego = COST_DIEGO * (numCups - int(numCups / LOYALTY_DIEGO))

print("Total Cost: £" + str(totalDiego))

Gold

Console.Write("How many cups of coffee would you like? ");
int numCups = Convert.ToInt32(Console.ReadLine());

const double COST_DIEGO = 1.4;
const int LOYALTY_DIEGO = 7;
double totalDiego = COST_DIEGO * (numCups - numCups / LOYALTY_DIEGO);

const double COST_FAROE = 1.3;
const int LOYALTY_FAROE = 11;
double totalFaroe = COST_FAROE * (numCups - numCups / LOYALTY_FAROE);

if(totalDiego < totalFaroe)
{
    Console.WriteLine("Diego's Coffee is cheaper!");
} else
{
    Console.WriteLine("Caffè Faroe is cheaper!");
}
numCups = int(input("How many cups of coffee would you like? "))

COST_DIEGO = 1.4
LOYALTY_DIEGO = 7
totalDiego = COST_DIEGO * (numCups - int(numCups / LOYALTY_DIEGO))

COST_FAROE = 1.3
LOYALTY_FAROE = 11
totalFaroe = COST_FAROE * (numCups - int(numCups / LOYALTY_FAROE))

if totalDiego < totalFaroe:
    print("Diego's Coffee is cheaper!")
else:
    print("Caffè Faroe is cheaper!")

 

Feel free to contact me with any questions! New challenge coming soon…