// ========================================================================== // $Id: bmi.go,v 1.1 2014/03/27 03:27:49 jlang Exp $ // CSI2120 GO: Functions with error codes // ========================================================================== // (C)opyright: // // Jochen Lang // EECS, University of Ottawa // 800 King Edward Ave. // Ottawa, On., K1N 6N5 // Canada. // http://www.eecs.uottawa.ca // // Creator: Jochen Lang (based on example by R. Laganiere) // Email: jlang@eecs.uottawa.ca // ========================================================================== // $Log: bmi.go,v $ // Revision 1.1 2014/03/27 03:27:49 jlang // Created Go examples for intro lecture. // // ========================================================================== package main import "fmt" func bmi(height float64, weight float64) (float64, bool) { if height > 0.0 { return weight / (height*height), true } else { return 0.0, false } } func main() { if value, ok := bmi(1.50, 55); ok { fmt.Printf("BMI: %f\n", value) } }