Created
September 15, 2012 23:14
-
-
Save maxenglander/3730294 to your computer and use it in GitHub Desktop.
Becca Brenneis A2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Syntax errors:
using namespace std;
above line 5Int
->int
;
not a:
>>
should be<<
; also missing a"
cin
should be separated: one forx
and one fory
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:
/tmp/becca_a2.cpp
.g++ /tmp/becca_a2.cpp -o /tmp/becca_a2
/tmp/becca_a2