-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterstellarTravelProject.go
59 lines (46 loc) · 1.14 KB
/
interstellarTravelProject.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
package main
import "fmt"
func fuelGauge(fuel int) {
fmt.Println(fuel)
}
func calculateFuel(planet string) int {
var fuel int
if planet == "Venus" {
fuel = 300000
fmt.Println("Venus costs 300000 pounds of fuel")
} else if planet == "Mecury" {
fuel = 500000
fmt.Println("Mecury costs 500000 pounds of fuel")
} else if planet == "Mars" {
fuel = 700000
fmt.Println("Mars costs 700000 pounds of fuel")
} else {
fuel = 0
}
return fuel
}
func greetPlanet(planet string) {
fmt.Println("Greetings earthlings, welcome to", planet)
}
func cantFly() {
fmt.Println("We do not have the available fuel to fly there")
}
func flytoPlanet(planet string, fuel int) int {
var fuelRemaining int
var fuelCost int
fuelRemaining = fuel
fuelCost = calculateFuel(planet)
if fuelRemaining > fuelCost {
greetPlanet(planet)
fmt.Println(fuelRemaining-fuelCost, "pounds of fuel remaining!")
} else {
cantFly()
}
return fuelRemaining
}
func main() {
fmt.Println("Welcome to Interstellar airlines!")
fuel := 1000000
planetChoice := "Venus"
fuel = flytoPlanet(planetChoice, fuel)
}