# 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: 3b: 4 4 #2 a: 5b: 2 5 #3 a: 6b: 6 6 #4 a: 12b: 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: 10Score #2: 20Score #3: 30 20 #2 Score #1: 0Score #2: 0Score #3: 30 10 #3 Score #1: 50Score #2: 50Score #3: 50 50 #4 Score #1: 20Score #2: 70Score #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: 15Gap: 5 Age: 20 #2 Age: 18Gap: 30 Age: 48 #3 Age: 20Gap: 80 Age: 100

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 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: YesRainy: YesSnowy: NoWindy: Yes You might see a rainbow today!Wear a raincoat!Have a good day! #2 Sunny: NoRainy: YesSnowy: NoWindy: No Take your umbrella!Have a good day! #3 Sunny: NoRainy: NoSnowy: YesWindy: 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: 90

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

As you found this challenge interesting...