ROUND, RANDOM and a trace · ROUND、RANDOM およびトレース
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · このページには最新のブラウザ(SharedArrayBuffer対応)が必要です。Chrome、Edge、Firefox、Safariを最新バージョンに更新してください。
A shop rounds a price
ROUND(Value, Places)returnsValuerounded toPlacesdecimal places.Placesis an integer.ROUND(3.14159, 2)is3.14.ROUND(9.6, 0)is the whole number10.- The syllabus lists
ROUNDwithDIV,MODandRANDOM.
OUTPUT ROUND(3.14159, 2)
OUTPUT ROUND(9.6, 0)
A dice uses RANDOM
RANDOM()returns a real from 0 to 1, including both ends. Each run can differ.- A board-game dice is
ROUND(RANDOM() * 6, 0). The paper uses it when the result may vary, so you are not asked for one fixed output.
OUTPUT ROUND(RANDOM() * 6, 0)
Fill a trace table
- A trace table is a dry run. One row is one pass of the loop. You write the variables after that pass.
Totalstarts at 0. AfterI = 1it is 1. AfterI = 2it is 3. AfterI = 3it is 6.
| I | Total |
|---|---|
| 1 | 1 |
| 2 | 3 |
| 3 | 6 |
Explore · 探索
One row per pass · 各パスごとに1行
A trace table records each variable after that pass of the loop. Here Total is the running sum of I. · トレーステーブルはループの各パス後に各変数を記録する。ここでは Total は I の累計である。
DECLARE I, Total : INTEGER
Total ← 0
FOR I ← 1 TO 3
Total ← Total + I
OUTPUT I, " ", Total
NEXT I
Watch out
- Round a half only when you have checked the digit. The tasks here are not on a halfway value.
RANDOM()is notRAND.RANDbelongs to the 9618 guide, not to this syllabus.
Common mistakes
ROUNDtakes the value first and the number of places second.- In a trace, record the values after the line has run, not the values you hope the next line will produce.
Now you try
- The first task is
ROUND. The second prints a trace, one row per line. - Press Check answer to test it.
Output ROUND(3.14159, 2) and ROUND(9.6, 0), each on its own line. · ROUND(3.14159, 2)とROUND(9.6, 0)を、それぞれ別々の行に出力します。
Click Run to see the output here. · 実行ボタンをクリックして出力を確認してください。
Start Total at 0. For I from 1 to 3, add I to Total and output I, a space, and Total on that line. The three lines are the trace. · Total を 0 で初期化せよ。I が 1 から 3 までで、I を Total に加算し、その行に I、スペース、Total を出力せよ。3つの行がトレースとなる。
Click Run to see the output here. · 実行ボタンをクリックして出力を確認してください。