Advertisement
Spocoman

Calorie Calculator

Oct 3rd, 2024
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 1.09 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.   "fmt"
  5.   "math"
  6.   "bufio"
  7.   "os"
  8. )
  9.  
  10. func main() {
  11.     var gender string
  12.     fmt.Scanln(&gender)
  13.    
  14.     var weight, height, basalMetabolicRate, coefficientActivity float64
  15.     fmt.Scanln(&weight)
  16.     fmt.Scanln(&height)
  17.  
  18.     var age int
  19.     fmt.Scanln(&age)
  20.    
  21.     scanner := bufio.NewScanner(os.Stdin)
  22.     scanner.Scan()
  23.     physicalActivity := scanner.Text()
  24.    
  25.     if gender == "m" {
  26.         basalMetabolicRate = 66 + weight * 13.7 + height * 500 - 6.8 * float64(age)
  27.     } else {
  28.         basalMetabolicRate = 655 + weight * 9.6 + height * 180 - 4.7 * float64(age)
  29.     }
  30.  
  31.     switch physicalActivity {
  32.         case "sedentary":
  33.             coefficientActivity = 1.2
  34.         case "lightly active":
  35.             coefficientActivity = 1.375
  36.         case "moderately active":
  37.             coefficientActivity = 1.55
  38.         default:
  39.             coefficientActivity = 1.725
  40.     }
  41.  
  42.     calories := int(math.Ceil(basalMetabolicRate * coefficientActivity))
  43.     fmt.Printf("To maintain your current weight you will need %d calories per day.\n", calories)
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement