LoginSignup
0
0

More than 1 year has passed since last update.

値に名前をつけて平均点を求める

Posted at

基礎からまた復習するため、メモ。

問題

国語が80点、英語が50点、数学が70点の場合のテストの平均点をターミナルに出力しろという時。

回答

practise.rb
japanese_score = 80
english_score = 50
math_score = 70

average = (japanese_score + english_score + math_score) / 3

puts "3教科の平均点は、#{average}点です。"

各教科の変数に点数の値をそれぞれ代入し、今度は各教科の平均を求めた計算結果をaverageという変数に代入。
ターミナルに出力する際は文字列と数値の組み合わせだから式展開で記述しとく。

0
0
2

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