- 2
functions in golang
Age on Mars How old would you be on Mars? A year on Earth has 365 days, while a year on Mars has 687 days. Create a program that takes your age in Earth years as input, and outputs the corresponding age on Mars. The given program takes an integer as input and passes it to the mars_age() function as argument. Complete the function to calculate and return the corresponding Mars age. Sample Input: 42 Sample Output: 22
10 Réponses
+ 13
package main
import "fmt"
func main() {
var age int
fmt.Scanln(&age)
mars := age * 365 / 687
fmt.Println(mars)
}
these the ans just go and past and enjoy your course....😊👍
+ 3
Thank you though. Cheers !
+ 1
This should be the Solution they want to see:
package main
import "fmt"
func mars_age(agemars int) int{
return agemars * 365 / 687
}
func main() {
var age int
fmt.Scanln(&age)
mars := mars_age(age)
fmt.Println(mars)
}
0
Hint:
Multiply <age-on-earth> by number of days in earth year (365)
Then divide the result by number of days in Mars year (687)
0
I need the whole code itself kindly @lpang
0
Victor,
I haven't studied Go, so I can provide you hints only : )
0
Good luck Victor 👍
0
No one can help me on this code?
0
Thanks @Amit. Code still not working though
- 1
package main
import "fmt"
func main() {
fmt.Println("This program will calculate how old you will be on a different planet")
fmt.Println("Pick a planet")
var planet string
fmt.Scanln(&planet)
fmt.Println("How old are you? ")
var age int
fmt.Scanln(&age)
switch planet{
case "Mercury", "mercury", "MERCURY":
fmt.Println("You will be", age * 365 / 88, "on Mercury.")
case "Venus", "venus", "VENUS":
fmt.Println("You will be", age * 365 / 225, "on Venus.")
case "Earth", "earth", "EARTH":
fmt.Println("You will be", age * 365 / 365, "on Earth.")
case "Mars", "mars", "MARS":
fmt.Println("You will be", age * 365 / 687, "on Mars")
case "Jupiter","jupiter","JUPITER":
fmt.Println("You will be", age * 365 / 4333, "on Jupiter.")
case "Saturn", "saturn", "SATURN":
fmt.Println("You will be", age * 365 / 10759, "on Saturn." )
case "Uranus", "uranus", "URANUS":
fmt.Println("You will be", age * 365 / 30687, "on Uranus.")
case "Neptune", "neptune", "NEPTUNE":
fmt.Println("You will be", age * 365 / 60190, "on Neptune")
}
}