In: Computer Science
Extract errors from the following codes & then obtain
weather they are Syntax
Error or Run Time Error? [15 pts]
a) [2 pts]
1 Dim number1 As Integer
2 Dim number2 As Integer
3 Dim result As Integer
4
5 number1 = (4 * 6 ^ 4) / (10 Mod 4 – 2)
6 number2 = (16 \ 3) ^ 2 * 6 + 1
7 result = number1 - number2
Line# / Error Description /Error Type (Syntax or Runtime) /Correction
b) [4pts]
1 Dim number1 As Double
2 Dim number2 Double
3 Dim result As Char
4
5 number1 = (4 ^ 2)
6 number2 = (16 \ 2)
7 result = number1 \ number2
Line# /Error Description /Error Type (Syntax or Runtime) /Correction
Hi,
In the first Expression,
There is a Compile Time Error and this is caused because of the below statement:
Error at line no - 5
Error description/Type - Compile Time Error
Correction:
number1 = (4 * 6 ^ 4) / (10 Mod 4 – 2)
To resolve this, you can replace
number1 = (4 * (6 ^ 4) / (10 Mod 4)) - 2
Note: Divider should more than 0 so above statement will wok because
=============================================================================
In the second Expression:
Error Line no - 2
Error Description - End of statement expected - Compile Time Error
Correction: To resolve the above error we need to declare the variable as below:
Dim number2 As Double
Again You can observe that Erro Line no - 7
Error Description: 'Long' value cannot be converted to 'char' - Compile time
Correction: result = Convert.ToChar(number1 \ number2)
Thanks