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...
The files provided contain syntax and/or logic errors. In each case, determine and fix the problem,...
The files provided contain syntax and/or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors, and run the program to ensure it works properly. 3. public abstract class DebugBoat {    String boatType = new String();    int passengers    String power = new String();    public FebugBoat(String bt)    {       boatType = bt;    }    public boolean equals(otherBoat)    {       boolean result;       if((passengers == otherBoat.passengers) && (power.equals(otherBoat.power)))          result = true;       else          result = true;       return result    }    public String...
1) The provided file has syntax and/or logical errors. Determine the problem(s) and fix the program....
1) The provided file has syntax and/or logical errors. Determine the problem(s) and fix the program. Grading When you have completed your program, click the Submit button to record your score. // Uses DisplayWebAddress method three times using static System.Console; class DebugSeven1 { static void Main() { DisplayWebAddress; Writeline("Shop at Shopper's World"); DisplayWebAddress; WriteLine("The best bargains from around the world"); DisplayWebAddres; } public void DisplayWebAddress() { WriteLine("------------------------------"); WriteLine("Visit us on the web at:"); WriteLine("www.shoppersworldbargains.com"); WriteLine("******************************"); } } 2) The provided...
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...
Can someone please fix my program? I keep getting a syntax error. Thanks (Python) from tkinter...
Can someone please fix my program? I keep getting a syntax error. Thanks (Python) from tkinter import * class LoanCalculator: def __init__(self): window = Tk() window.title("Loan Calculator") Label(window,text = "Annual Interest Rate").grid(row = 1, column = 1, sticky = W) Label(window,text = "Number of Years").grid(row = 2, column = 1, sticky = W) Label(window,text = "Loan Amount").grid(row = 3, column = 1, sticky = W) Label(window,text = "Monthly Payment").grid(row = 4, column = 1, sticky = W) Label(window,text = "Total...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT