feat(main): do price validation

This commit is contained in:
2026-02-25 23:37:55 +03:00
parent e1c1b718ef
commit e20c067a60

View File

@@ -15,8 +15,22 @@ fun main() {
println("введите имя")
val name = readLine() ?: "default"
println("введите цену")
val price = readLine()?.toLongOrNull() ?: 0L
var price: Long?
do {
println("введите цену:")
var input = readLine()
price = input?.toLongOrNull()
if (price == null) {
println("цена должна быть числом")
} else if (price <= 0) {
println("цена должна быть больше 0")
price = null
}
}
while (price == null)
val newProduct =
Product(