- 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

6th Jul 2021, 9:45 AM
VICTOR JACOB BUSAKA
VICTOR JACOB BUSAKA - avatar
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....😊👍
28th Jul 2021, 6:44 PM
Sagar Mukesh Thakur
Sagar Mukesh Thakur - avatar
+ 3
Thank you though. Cheers !
6th Jul 2021, 9:54 AM
VICTOR JACOB BUSAKA
VICTOR JACOB BUSAKA - avatar
+ 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) }
29th Aug 2022, 7:24 AM
Simone Piccolo
Simone Piccolo - avatar
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)
6th Jul 2021, 9:50 AM
Ipang
0
I need the whole code itself kindly @lpang
6th Jul 2021, 9:52 AM
VICTOR JACOB BUSAKA
VICTOR JACOB BUSAKA - avatar
0
Victor, I haven't studied Go, so I can provide you hints only : )
6th Jul 2021, 9:53 AM
Ipang
0
Good luck Victor 👍
6th Jul 2021, 9:56 AM
Ipang
0
No one can help me on this code?
7th Jul 2021, 10:44 AM
VICTOR JACOB BUSAKA
VICTOR JACOB BUSAKA - avatar
0
Thanks @Amit. Code still not working though
27th Jul 2021, 1:05 PM
VICTOR JACOB BUSAKA
VICTOR JACOB BUSAKA - avatar
- 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") } }
25th Jul 2021, 1:10 AM
AMIT KUSHWAHA
AMIT KUSHWAHA - avatar