-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.kt
29 lines (26 loc) · 915 Bytes
/
Main.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package converter
fun main() {
val converter = Converter()
initialPrompt(converter)
}
fun initialPrompt(converter: Converter) {
while (true) {
print("Enter two numbers in format: {source base} {target base} (To quit type /exit) ")
when (val selection = readln()) {
"/exit" -> return
else -> {
val (sourceBase, targetBase) = selection.split(" ").map { it.toInt() }
convertPrompt(converter, sourceBase, targetBase)
}
}
}
}
fun convertPrompt(converter: Converter, sourceBase: Int, targetBase: Int) {
while (true) {
print("Enter number in base $sourceBase to convert to base $targetBase (To go back type /back) ")
when (val selection = readln()) {
"/back" -> println().also { return }
else -> converter.convert(selection, sourceBase, targetBase)
}
}
}