Skip to content

Instantly share code, notes, and snippets.

@cancel-cloud
Created February 26, 2023 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cancel-cloud/622c197580327584bc5af2617f54dc64 to your computer and use it in GitHub Desktop.
Save cancel-cloud/622c197580327584bc5af2617f54dc64 to your computer and use it in GitHub Desktop.
CoffeMachineCalculator
fun main() {
println("Write how many ml of water the coffee machine has:")
print("> ")
val water = readLine()!!.toInt()
println("Write how many ml of milk the coffee machine has:")
print("> ")
val milk = readLine()!!.toInt()
println("Write how many grams of coffee beans the coffee machine has:")
print("> ")
val beans = readLine()!!.toInt()
println("Write how many cups of coffee you will need:")
print("> ")
val cups = readLine()!!.toInt()
val waterPerCup = 200
val milkPerCup = 50
val beansPerCup = 15
val maxCups = minOf(water / waterPerCup, milk / milkPerCup, beans / beansPerCup)
when {
maxCups == cups -> println("Yes, I can make that amount of coffee")
maxCups > cups -> println("Yes, I can make that amount of coffee (and even ${maxCups - cups} more than that)")
else -> println("No, I can make only $maxCups cup(s) of coffee")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment