Find the Logic Error

Check the following pieces of code. The syntax of the code is correct and the programs do run. However, while testing these programs, you will notice that they do not always produce the expected output! This is because each program contains a logic error. Can you spot and fix these logic errors?

Program 1:Program 2:Program 3:Program 4:Program 5:Program 6:

Higher or Lower?


The aim of this program is to identify the highest number from 2 user inputs:

Test Plan:

Test # Input Values Expected Output Actual Output
#1 a: 3
b: 4
4
#2 a: 5
b: 2
5
#3 a: 6
b: 6
6
#4 a: 12
b: 4
12

Average Score?


The aim of this program is to calculate the average score out of 3 scores:

Test Plan:

Test # Input Values Expected Output Actual Output
#1 Score #1: 10
Score #2: 20
Score #3: 30
20
#2 Score #1: 0
Score #2: 0
Score #3: 30
10
#3 Score #1: 50
Score #2: 50
Score #3: 50
50
#4 Score #1: 20
Score #2: 70
Score #3: 30
40

Your age in the future?


The aim of this program is to calculate how old you will be in a given number of years:

Test Plan:

Test # Input Values Expected Output Actual Output
#1 Age: 15
Gap: 5
Age: 20
#2 Age: 18
Gap: 30
Age: 48
#3 Age: 20
Gap: 80
Age: 100

What’s my grade?


The aim of this program is for the user to input a test score and for the program to output a grade as follows:

  • Any score below 50 should receive a U grade
  • Any score between 50 and 69 should receive a Pass grade
  • Any score between 70 and 89 should receive a Merit grade
  • Any score of 90 or above should receive a Distinction grade


Test Plan:

Test # Input Values Expected Output Actual Output
#1 Score: 30 Grade: U
#2 Score: 65 Grade: Pass
#3 Score: 82 Grade: Merit
#4 Score: 97 Grade: Distinction
#5 Score: 102 Invalid Score!
#6 Score: 0 Grade: U
#7 Score: 50 Grade: Pass
#8 Score: 69 Grade: Pass
#9 Score: 70 Grade: Merit
#10 Score: 89 Grade: Merit
#11 Score: 90 Grade: Distinction
#12 Score: 100 Grade: Distinction

Tip of the day!


The aim of this program is to generate a tip of the day based on the weather conditions.

Test Plan:

Test # Input Values Expected Output Actual Output
#1 Sunny: Yes
Rainy: Yes
Snowy: No
Windy: Yes
You might see a rainbow today!
Wear a raincoat!
Have a good day!
#2 Sunny: No
Rainy: Yes
Snowy: No
Windy: No
Take your umbrella!
Have a good day!
#3 Sunny: No
Rainy: No
Snowy: Yes
Windy: Yes
Wear a raincoat!
Have a good day!

Factorial!


The aim of this program is to calculate the factorial of any given number. e.g. 5! = 5x4x3x2x1 = 120

Test Plan:

Test # Input Values Expected Output Actual Output
#1 5 5! = 120
#2 10 10! = 3628800
#3 0 0! = 1

Did you like this challenge?

Click on a star to rate it!

Average rating 3.2 / 5. Vote count: 133

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!