In a science experiment, result X is expected to occur 25% of the time and result Y is expected to occur the remaining 75% of the time. The following code segment is intended to simulate the experiment if there are 100 trials. Line 1: xCount 0 Line 2: yCount ← 0 Line 3: REPEAT 100 TIMES Line 4: { Line 5: IF(RANDOM (1, 4) = 1) Line 6: { Line 7: xCountxCount + 1 Line 8: } Line 9: IF(RANDOM (1, 4) > 1) Line 10: { Line 11: yCountyCount + 1 Line 12: } Line 13: } Line 14: DISPLAY ("Result X occurred") Line 15: DISPLAY (xCount) Line 16: DISPLAY ("times and result Y occurred") Line 17: DISPLAY (yCount) Line 18: DISPLAY("times.") A programmer runs the code segment, and the following message is displayed. Result X occurred 24 times and result Y occurred 70 times. The result shows that 94 trials were counted, rather than the intended 100 trials. Which of the following changes to the code segment will ensure a correct simulation of the experiment? A Replacing line 9 with IF (RANDOM (1, 4) ≥ 2) B Replacing line 9 with ELSE C Interchanging lines 5 and 9 D Interchanging lines 7 and 11

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter5: Repetition Statements
Section5.5: A Closer Look: Loop Programming Techniques
Problem 14E
icon
Related questions
Question
In a science experiment, result X is expected to occur 25% of the time and result Y is expected to occur the
remaining 75% of the time. The following code segment is intended to simulate the experiment if there are
100 trials.
Line 1: xCount 0
Line 2:
yCount ← 0
Line 3:
REPEAT 100 TIMES
Line 4:
{
Line 5:
IF(RANDOM (1, 4) = 1)
Line 6:
{
Line 7:
xCountxCount + 1
Line 8:
}
Line 9:
IF(RANDOM (1, 4) > 1)
Line 10:
{
Line 11:
yCountyCount + 1
Line 12: }
Line 13: }
Line 14: DISPLAY ("Result X occurred")
Line 15: DISPLAY (xCount)
Line 16: DISPLAY ("times and result Y occurred")
Line 17: DISPLAY (yCount)
Line 18: DISPLAY("times.")
A programmer runs the code segment, and the following message is displayed.
Result X occurred 24 times and result Y occurred 70 times.
The result shows that 94 trials were counted, rather than the intended 100 trials. Which of the following
changes to the code segment will ensure a correct simulation of the experiment?
A
Replacing line 9 with IF (RANDOM (1, 4) ≥ 2)
B
Replacing line 9 with ELSE
C
Interchanging lines 5 and 9
D Interchanging lines 7 and 11
Transcribed Image Text:In a science experiment, result X is expected to occur 25% of the time and result Y is expected to occur the remaining 75% of the time. The following code segment is intended to simulate the experiment if there are 100 trials. Line 1: xCount 0 Line 2: yCount ← 0 Line 3: REPEAT 100 TIMES Line 4: { Line 5: IF(RANDOM (1, 4) = 1) Line 6: { Line 7: xCountxCount + 1 Line 8: } Line 9: IF(RANDOM (1, 4) > 1) Line 10: { Line 11: yCountyCount + 1 Line 12: } Line 13: } Line 14: DISPLAY ("Result X occurred") Line 15: DISPLAY (xCount) Line 16: DISPLAY ("times and result Y occurred") Line 17: DISPLAY (yCount) Line 18: DISPLAY("times.") A programmer runs the code segment, and the following message is displayed. Result X occurred 24 times and result Y occurred 70 times. The result shows that 94 trials were counted, rather than the intended 100 trials. Which of the following changes to the code segment will ensure a correct simulation of the experiment? A Replacing line 9 with IF (RANDOM (1, 4) ≥ 2) B Replacing line 9 with ELSE C Interchanging lines 5 and 9 D Interchanging lines 7 and 11
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT