'I need to find the logic error in my tp - pseudocode
At school, I have a Pseudocode problem. I need to print every number from 0 to 99, and when the number can be divided by 3, it needs to also type "Boo" beside the number. If it can be divided by 5, it needs to "type" Phew beside that number, e.g.
2
3 Boo
4
5 Phew
6 Boo
They are asking it in pseudocode. Here's what I tried to do, but my teacher says the logic is not good enough:
int i = 0;
WHILE i < 100 DO
print i to screen
IF i%3 = 0 THEN
Print " Boo" to screen
ELSE IF i%5 = 0 THEN
print " Phew" to screen
END IF
Switch lines on screen
i = i+ 1
END WHILE
Does anyone know how I could fix this?
Solution 1:[1]
May not work as there are different "styles" of pseudocode:
int i = 0;
WHILE i < 100 DO:
print i
IF int(i % 3) == true THEN:
three == true
ELSE:
three == false
IF int(i % 5) == true THEN:
five == true
ELSE:
five == false
IF three == true AND five == false THEN:
print i, " Boo"
ELIF five == true AND three == false THEN:
print i, " Phew"
ELIF five == true AND three == true ?THEN:
?print i, ,"Boo", " Phew"
ELIF five == false AND three == false ?THEN:
?print i
ENDIF
i = i + 1
ENDWHILE
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
