Lecture 4 - Control Structures II (Repetition)
Lecture 4 - Control Structures II (Repetition)
Programming 2
MEK 3100
Lecture 4
Why Is Repetition Needed?
• Repetition allows you to efficiently use variables
• The program uses the function rand of the header file cstdlib
to generate a random number
✓ rand() returns an int value between 0 and 32767
✓To convert it to an integer greater than or equal to 0 and less than
100:
o rand() % 100
for Looping (Repetition)
Structure
• The general form of the for statement is:
• Answer:
*****
****
***
**
*