Assigning values to struct fields

Report a typo

Below you will see a Go program with a declaration of the Country struct.

Create an instance of the Country struct within the variable germany and assign values to its fields by using a struct literal or by assigning values to each individual field. The Name of the country is Germany, the Capital is Berlin and the Currency is Euro.

Finally, the program should print each of the germany struct fields, each on a new line.

Write a program in Go
package main

import "fmt"

// do not change the name or the fields of the 'Country' struct!
type Country struct {
Name string
Capital string
Currency string
}

func main() {
// create an instance of the Country struct within the 'germany' variable here.
// do not forget to assign the values mentioned above to its fields too!
var germany ?

?.? = ? // assign the value 'Germany' to the 'Name' field here
?.? = ? // assign the value 'Berlin' to the 'Capital' field here
?.? = ? // assign the value 'Euro' to the 'Currency' field here

// Print the struct fields in order Name->Capital->Currency each on a new line:
fmt.Printf("%s\n%s\n%s\n", ?.?, ?.?, ?.?)
}
___

Create a free account to access the full topic