Skip to content

Instantly share code, notes, and snippets.

@maxenglander
Created September 15, 2012 23:14
Show Gist options
  • Save maxenglander/3730294 to your computer and use it in GitHub Desktop.
Save maxenglander/3730294 to your computer and use it in GitHub Desktop.
Becca Brenneis A2
#include <iostream> // required for cin, cout, edl.
#include <cmath> // required for sqrt()
Int main()
{
//Declare objects and
double x1, y1, x2, y2, side1, side2, distance;
side1 = x2 –x1;
side2 = y2 – y1;
distance = sqrt(side1 * side2);
// prompt user for input
cout << “Please enter x1” << “Please enter y1”;
cin >> x1 >> y1:
cout << “Please enter x2 << “Please enter y2” ;
cin >> x2 >> y2;
cout >> “The distance between (x1, y1) and (x2, y2) is >> distance;
return0;
}
@maxenglander
Copy link
Author

Syntax errors:

  • You should declare using namespace std; above line 5
  • Line 5: Int -> int
  • Line 16: should terminate with a ; not a :
  • Line 19: >> should be <<; also missing a "
  • Lines 15-18: Each "Please enter" and cin should be separated: one for x and one for y
  • Lint 21: return0 -> return 0

Logical errors:

You are running your calculations before you've read in the values from the user. You should be declaring your variables (which you do on line 9), then reading in the values from the user (lines 15-18), then running the calculations (lines 10-12), then reporting the results (line 19).

To compile:

  1. Copy the code to a file locally, say /tmp/becca_a2.cpp.
  2. Run the command g++ /tmp/becca_a2.cpp -o /tmp/becca_a2
  3. Run the result /tmp/becca_a2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment