-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtravel.go
65 lines (53 loc) · 1.21 KB
/
travel.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import "fmt"
// Create the function fuelGauge() here
func fuelGauge(fuel int) {
fmt.Println("you have", fuel, "gallons of fuel left")
}
// Create the function calculateFuel() here
func calculateFuel(planet string) int {
var fuel int
switch planet {
case "Venus":
fuel = 300000
case "Mercury":
fuel = 5000000
case "Mars":
fuel = 7000000
default:
fuel = 0
}
return fuel
}
// Create the function greetPlanet() here
func greetPlanet (planet string) {
fmt.Println("welcome to planet", planet)
}
// Create the function cantFly() here
func cantFly () {
fmt.Println("we do not have the availble fuel to fly there.")
}
// Create the function flyToPlanet() here
func flyToPlanet (planet string, fuel int) int {
var fuelRemaining, fuelCost int
fuelRemaining = fuel
fuelCost = calculateFuel(planet)
if fuelRemaining >= fuelCost {
greetPlanet(planet)
fuelRemaining -= fuelCost
} else {
cantFly()
}
return fuelRemaining
}
func main() {
// Test your functions!
// Create `planetChoice` and `fuel`
var fuel int
fuel = 1000000
var planetChoice string
planetChoice = "Venus"
// And then liftoff!
fuel = flyToPlanet(planetChoice, fuel)
fuelGauge(fuel)
}