Module 4 Debugging Exercise Please submit your corrections to the debugging exer
ID: 3587164 • Letter: M
Question
Module 4 Debugging Exercise Please submit your corrections to the debugging exercises in the attached file ( stating out with logic and design). Repetition Structures. find the error, please.
1-Declare Integer product, number
product = 0
While product < 100
Display "Enter a number."
Input number
End While
2- Declare Real num1, num2, sum
Declare String again
Do
Display "Enter a number."
Input num1
Display "Enter another number."
Input num2
Set sum = num1 + num2
Display "Their sum is ", sum
Display "Do you want to do that again? (y=yes)"
Input again
3- Declare Integer num
While num < 10
Display "Enter a number."
Input num
Set num = num + 1
End While
4- Declare Integer year = 1
Declare Integer month = 1
While year < 10
Display “This is year “, year.
While month < 12
Display “This is month “, month
End While
Set month = month + 1
Set year = year + 1
End While
5- Declare Integer week = 1
Declare Integer day = 1
While week <= 52
Display “This is week “, week.
While day <= 8
Display “This is day “, day
Set day = day + 1
End While
Set week = week + 1
End While
Explanation / Answer
1 While Loop executes and check the value of product which is initially 0 , so it enters the loop but inside loop the value of number is inputted not of product . So value of product remains unchanged which leads to infinite loop as product is always equal to 0.
2. The loop does not end with condition. With a Do, While(Condition) is required.
3. The value of num is not initialized . So While(num < 10) cannot be executed. The condition variable needs to be initialized.
4. Inside inner loop
While month < 12
Display “This is month “, month
End While
the month should be incremented by Set month = month + 1
But here the month is incremented outside the inner loop.
So inner while loop will not work correctly as value of month is always 1 leads to infinite loop.
5. Here the inner loop condition should be While day <=7 as there are 7 days in a week.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.