Created
February 26, 2023 16:44
-
-
Save cancel-cloud/622c197580327584bc5af2617f54dc64 to your computer and use it in GitHub Desktop.
CoffeMachineCalculator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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