Question

In: Computer Science

Extract errors from the following codes & then obtain weather they are Syntax Error or Run...

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

Solutions

Expert Solution

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

  1. 10 Mod 4 - 2 will return 0
  2. (10 Mod 4) - 2 also returns 0
  3. 10 Mod (4-2) also returns 0

=============================================================================

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


Related Solutions

C++ : Find the syntax errors in the following program. For each syntax error, fix it...
C++ : Find the syntax errors in the following program. For each syntax error, fix it and add a comment at the end of the line explaining what the error was. #include <iostream> #include <cmath> using namespace std; int main(){ Double a, b, c; 2=b; cout<<"Enter length of hypotenuse"<<endl; cin>>c>>endl; cout>>"Enter length of a side"<<endl; cin>>a; double intermediate = pow(c, 2)-pow(a, 2); b = sqrt(intermediate); cout<<"Length of other side is:" b<<endline; return 0; }
Question #1 The commented codes in the Driver class are either causing a syntax error or...
Question #1 The commented codes in the Driver class are either causing a syntax error or run time error. Make sure to identify the error yourself without running it. predict the output once you fix all the errors. un-comment one line at a time identify the error fix just that line, You are not allowed to change any declarations of the objects. if it is a runtime error explain the error compile the code. move to the next error Make...
Please identify each error present, explain the type of error (syntax/logic/run-time), and provide a fix which...
Please identify each error present, explain the type of error (syntax/logic/run-time), and provide a fix which changes the given code as little as possible (i.e. don't rewrite the whole thing; just point out what is wrong and a fix for it). 5) // Assign a grade based on the score char score; cin>>score; if score < 0 && score > 100     cout<<"The score entered is invalid"<<endl; if (score <= 90)     grade = "A"; if (score <= 80)    ...
identify the syntax errors in the following code:             public class Hello {                    &
identify the syntax errors in the following code:             public class Hello {                         private static int main(String [] args) {                                     string Msg=”Hello, Wrld!;                                     Sytem.out.println(msg+ “Ken")
Part 1: Find and fix errors and add following functionalities 1. There are several syntax errors...
Part 1: Find and fix errors and add following functionalities 1. There are several syntax errors in the code that are preventing this calculator from working, find and fix those errors. When they are fixed, the number buttons will all work, as well as the + (add) and -- (decrement) buttons. a. To find the errors, open up the Developers Tool of the browser and look at the console (F12). Verify the add functionality works. For a binary operator, you...
To earn full credit, program must be free of syntax, run-time, and logic errors; include program...
To earn full credit, program must be free of syntax, run-time, and logic errors; include program comments; use reasonable readable variable names and prompts. To include variables in the input prompt, you must use concatenation character (+). For example: assume you already asked for input of employee's first name and last name (they are stored into variables FirstName and LastName, then use this prompt to ask for employee's weekly hours which includes the employee's full name in the input statement....
The following code has some syntax error. Please fixed the error. Besides, I want the output...
The following code has some syntax error. Please fixed the error. Besides, I want the output in ASCII characters. Please give me the corrected code along with the screenshot of the output. def cbc_dec(ys): int xs = [] int iv = ("0XAA", 16) #in decimal int key = ("0X08", 16) int x0 = chr(((163 * (int (ys[0], 16) - key)) % 256) ^ iv) xs.append(x0) for i in range (1, len(ys)): int xi = chr((( 163 * (int (ys[i], 16)...
For each of the following Visual Basic code snippets, identify the syntax error.   If intX >...
For each of the following Visual Basic code snippets, identify the syntax error.   If intX > 100   lblResult.Text = "Invalid Data" End If   Dim str As String = "Hello" Dim intLength As Integer intLength = Length(str) If intZ < 10 Then   lblResult.Text = "Invalid Data"   Dim str As String = "123" If str.IsNumeric Then   lblResult.Text = "It is a number." End If   Select Case intX   Case < 0     lblResult.Text = "Value too low."   Case > 100     lblResult.Text = "Value too high."   Case Else     lblResult.Text = "Value...
Trial Balance Errors For each of the following errors, considered individually, indicate whether the error would...
Trial Balance Errors For each of the following errors, considered individually, indicate whether the error would cause the trial balance totals to be unequal. If the error would cause the trial balance totals to be unequal, indicate whether the debit or credit total is higher and by how much. If the debit and credit totals would be equal, enter zero ("0") in the amount box. a. The payment of an insurance premium of $7,450 for a three-year policy was debited...
The following errors are in the books of Mr. Hilal at end March 2017. The error...
The following errors are in the books of Mr. Hilal at end March 2017. The error committed is provided. Discuss the following for each of the below errors: The type of error committed; and Rectification Process (in words) and Rectify the error (entry)                                                             Machinery purchased from Mr. Rafiq RO. 8000 was entered into the Purchase book. Accounts Dr. Cr. Purchases                       Rafiq 8,000 8,000                      Credit sales to Fatima RO. 10,000 is debited wrongly to the account of Sharifa. Accounts...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT