-
Notifications
You must be signed in to change notification settings - Fork 0
/
rocket.go
61 lines (52 loc) · 1.16 KB
/
rocket.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
package main
import "fmt"
// Create the function fuelGauge() here
func fuelGauge(fuel int) {
fmt.Println("You have ", fuel, " gallons left.")
}
// Create the function calculateFuel() here
func calculateFuel(planet string) int {
var fuel int
switch planet {
case "Venus":
fuel = 300000
case "Mercury":
fuel = 500000
case "Mars":
fuel = 700000
default:
fuel = 0
}
return fuel
}
// Create the function greetPlanet() here
func greetPlanet(planet string) {
fmt.Println("Welcome to ", planet)
}
// Create the function cantFly() here
func cantFly() {
fmt.Println("We do not have the available 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 if fuelRemaining < fuelCost {
cantFly()
}
return fuelRemaining
}
func main() {
// Create `planetChoice` and `fuel`
var fuel int
var planetChoice string
fuel = 1000000
planetChoice = "Venus"
// And then liftoff!
fuel = flyToPlanet(planetChoice, fuel)
fuelGauge(fuel)
}