0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

main.go

Posted at

package main

import "fmt"

func main() {
totalScore := 0
// 引数にtotalScoreのポインタを渡してください
ask(1, "dog",&totalScore)
ask(2, "cat",&totalScore)
ask(3, "fish",&totalScore)

fmt.Println("スコア", totalScore)

}

// 渡されるtotalScoreのポインタを受け取るように変更してください
func ask(number int, question string, scorePtr *int) {
var input string
fmt.Printf("[質問%d] 次の単語を入力してください: %s\n", number, question)
fmt.Scan(&input)

if question == input {
	fmt.Println("正解!")
	// ポインタを使って加算してください
	*scorePtr += 10
	
} else {
	fmt.Println("不正解!")
}

}
ポインタを使って出力する

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?