Question

In: Computer Science

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;
}

Solutions

Expert Solution

Solution:

#include <iostream>

#include <cmath>

using namespace std;

int main(){

double a, b, c;

//Correct spelling of data type double is double not Double

b=2;

//Variable cannot be assigned to constant it should be other way around

cout<<"Enter length of hypotenuse"<<endl;

cin>>c;

//endl has to be removed after c

cout<<"Enter length of a side"<<endl;

//The operator after cout should be << not >>

cin>>a;

double intermediate = pow(c, 2)-pow(a, 2);

b = sqrt(intermediate);

cout<<"Length of other side is:" <<b<<endl;

//endl should be used to end a line not endline,b should be preceded by <<

return 0;

}

Output:


Related Solutions

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...
There are at least 10 errors in the following C program. For each error you can...
There are at least 10 errors in the following C program. For each error you can find you should list the location of the error, describe what the error is, and state how the error can be fixed (write updated code for that line if necessary). Each error you find is worth 1.5 marks. Note that missing brackets, braces, etc count as only one error, even though the missing brackets may occur at two places. The program is supposed to...
There are at least 10 errors in the following C program. For each error you can...
There are at least 10 errors in the following C program. For each error you can find you should list the location of the error, describe what the error is, and state how the error can be fixed (write updated code for that line if necessary). Each error you find is worth 1.5 marks. Note that missing brackets, braces, etc count as only one error, even though the missing brackets may occur at two places. The program is supposed to...
There are at least 10 errors in the following C program. For each error you can...
There are at least 10 errors in the following C program. For each error you can find you should list the location of the error, describe what the error is, and state how the error can be fixed (write updated code for that line if necessary). Each error you find is worth 1.5 marks. Note that missing brackets, braces, etc count as only one error, even though the missing brackets may occur at two places. The program is supposed to...
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)    ...
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)...
q7.4 Fix the errors in the code (in C) //This program is supposed to scan 5...
q7.4 Fix the errors in the code (in C) //This program is supposed to scan 5 ints from the user //Using those 5 ints, it should construct a linked list of 5 elements //Then it prints the elements of the list using the PrintList function #include <stdio.h> struct Node{ int data; Node* next; }; int main(void){ struct Node first = {0, 0}; struct Node* second = {0, 0}; Node third = {0, 0}; struct Node fourth = {0, 0}; struct...
q7.1 Fix the errors in the code (in C) //This program should read a string from...
q7.1 Fix the errors in the code (in C) //This program should read a string from the user and print it using a character pointer //The program is setup to use pointer offset notation to get each character of the string #include <stdio.h> #include <string.h> int main(void){ char s[1]; scanf(" %c", s); char *cPtr = s[1]; int i=0; while(1){ printf("%c", cPtr+i); i++; } printf("\n"); }
Analyze following program and Find Syntax errors. #include<iostream> int show(int x) int main() {     int A,B;...
Analyze following program and Find Syntax errors. #include<iostream> int show(int x) int main() {     int A,B;       char B=10; cout<<”Enter Value of A”; cin<<A; show(A) show(50)          }       cin.get(); } int show(int x); { cout<<”Value is =” <<X cout<<endl; }
Please fix all the errors in this Python program. import math def solve(a, b, c): """...
Please fix all the errors in this Python program. import math def solve(a, b, c): """ Calculate solution to quadratic equation and return @param coefficients a,b,class @return either 2 roots, 1 root, or None """ #@TODO - Fix this code to handle special cases d = b ** 2 - 4 * a * c disc = math.sqrt(d) root1 = (-b + disc) / (2 * a) root2 = (-b - disc) / (2 * a) return root1, root2 if...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT