adding cs142 code
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
include $(GOROOT)/src/Make.inc
|
||||
|
||||
TARG=temp
|
||||
GOFILES=\
|
||||
temp.go
|
||||
|
||||
include $(GOROOT)/src/Make.cmd
|
||||
@@ -0,0 +1,21 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func f2c(temp_F float32) float32 {
|
||||
return 5.0/9.0 * (temp_F-32);
|
||||
}
|
||||
|
||||
func main() {
|
||||
var temp_F float32
|
||||
fmt.Print("please enter a temperature: ")
|
||||
fmt.Scan(&temp_F)
|
||||
temp_C := f2c(temp_F)
|
||||
|
||||
fmt.Printf("%0.4fF as:\n", temp_F)
|
||||
fmt.Printf("an int: %dF\n", int(temp_F))
|
||||
fmt.Printf("a celsius float32: %0.4fC\n", temp_C)
|
||||
fmt.Printf("a celcius int: %dC\n", int(temp_C))
|
||||
}
|
||||
Reference in New Issue
Block a user