Difference between revisions of "2022 New Spec"
Line 13: | Line 13: | ||
S ← S + N1 + N2 | S ← S + N1 + N2 | ||
IF N1 = 6 OR N2 = 6 THEN | IF N1 = 6 OR N2 = 6 THEN | ||
− | + | C ← C + 1 | |
ENDIF | ENDIF | ||
IF N1 = N2 THEN | IF N1 = N2 THEN | ||
− | + | D ← D + 1 | |
ENDIF | ENDIF | ||
ENDWHILE | ENDWHILE |
Latest revision as of 09:08, 2 February 2023
Figure 3 shows an algorithm represented using pseudo-code.
Figure 3
C ← 0 D ← 0 S ← 0 T ← 0 WHILE C < 3 AND D < 3 T ← T + 1 N1 ← generate random integer between 1 and 6 inclusive N2 ← generate random integer between 1 and 6 inclusive OUTPUT N1, N2 S ← S + N1 + N2 IF N1 = 6 OR N2 = 6 THEN C ← C + 1 ENDIF IF N1 = N2 THEN D ← D + 1 ENDIF ENDWHILE A ← S DIV (T * 2) OUTPUT C, D, A
The DIV operator calculates the whole number part resulting from an integer division, for example, 10 DIV 3 = 3.
Table 4 lists the DIV operators for each of the available programming languages. You should refer to the row for your programming language.
Table 4
Programming Language | Div |
---|---|
C# | / |
Java | / |
Pascal | Div |
Python | // |
VB | \ |
What you need to do:
Task 1
Write a program to implement the algorithm in Figure 3.
Task 2
Test that your program works, run your program and get a screenshot.