Init commit

This commit is contained in:
Archie Fox
2025-02-24 15:49:59 +03:00
commit d1eea4bb66
5 changed files with 120 additions and 0 deletions

3
go-demo/go.mod Normal file
View File

@@ -0,0 +1,3 @@
module demo/app-1
go 1.23.6

69
go-demo/main.go Normal file
View File

@@ -0,0 +1,69 @@
package main
import (
"errors"
"fmt"
"math"
)
func main() {
fmt.Println("__ Калькулятор индекса массы тела __")
for {
userKg, userHeight := getUserInput()
IMT, err := calculateIMT(userKg, userHeight)
if err != nil {
// fmt.Println(err)
// continue
panic("Не заданы параметры для расчета")
}
outputResult(IMT)
fmt.Print("Хотите расчитать еще (Y/n): ")
var choice string
fmt.Scan(&choice)
if choice == "n" {
break
}
if choice == "Y" || choice == "y" {
continue
}
}
}
func outputResult(imt float64) {
result := fmt.Sprintf("Ваш индекс массы тела: %.1f\n", imt)
fmt.Print(result)
switch {
case imt < 16:
fmt.Println("У вас сильный дефицит массы тела")
case imt < 18.5:
fmt.Println("У вас дефицит массы тела")
case imt < 25:
fmt.Println("У вас нормальный вес")
case imt < 30:
fmt.Println("У вас избыточный вес")
default:
fmt.Println("У вас степень ожирения")
}
}
func calculateIMT(userKg float64, userHeight float64) (float64, error) {
const IMTPower float64 = 2
if userHeight <= 0 || userKg <= 0 {
return 0, errors.New("NO_VALID_PARAMS")
}
IMT := userKg / math.Pow(userHeight/100, IMTPower)
return IMT, nil
}
func getUserInput() (float64, float64) {
var userHeight float64
var userKg float64
fmt.Print("Введите свой рост в сантиметрах: ")
fmt.Scan(&userHeight)
fmt.Print("Введите свой вес в килограммах: ")
fmt.Scan(&userKg)
return userKg, userHeight
}