I\'m confused about this code and why this is not compling. the output and input
ID: 670685 • Letter: I
Question
I'm confused about this code and why this is not compling. the output and input is correct but my syntax i not working
#include <iostream>
using namespace std;
int main()
{
double x1; // x1 coord
double x2; // x2 coord
double y1; // y1 coord
double y2; // y2 coord
cout <<"Enter x1 and y1 (2 points) "; // promt user for x1 and y1
cin >> x1; // cord x1
cin >> y1; // cord y1
cout <<"Enter x2 and y2 (2 points) "; // promt user for x2 and y2
cin >> x2; // cord of x2
cin >> y2; //coord of y2
if ( x1 == x2 && y1 == y2) {
cout <<"Point (" << x2 << "," << y2 << ") equals point (" << x1 << "," << y1 << ").";
else if( x1 < x2 && y1 == y2) {
cout <<"Point (" << x2 << "," << y2 << ") is the right of point (" << x1 "," << y1 << ").";
}
else if ( x1 > x2 && y1 == y2 ) {
cout <<"Point (" << x2 << "," << y2 << ") is the left of point (" << x1 << "," << y1 <<)").";
}
else if ( x1 == x2 && y1 < y2) {
cout <<"Point (" << x2 << "," << y2 << ") is above the point (" << x1 "," << y1 <<").";
}
else if (x1 == x2 && y1 > y2) {
cout <<"Point (" << x2 << "," << y2 << ") is below the point (" << x1 << "," << y1").";
}
else if (x1 > x2 && y1 < y2 ) {
cout <<"Point (" << x2 << "," << y2 << ") is above and left of the point (" << x1 << "," << y1 ").";
}
else if (x1 < x2 && y1 < y2 ) {
cout <<"Point (" << x2 << "," << y2 << ") is above and right of the point (" << x1 << "," << y1 ").";
}
else if (x1 < x2 && y1 > y2 ) {
cout <<"Point (" << x2 << "," << y2 << ") is below and right of the point (" << x1 "," << y1 ").";
}
else (x1 > x2 && y1 > y2 ); cout <<"Point (" << x2 << "," << y2 << ") is below and left theh point (" << x1 "," << y1 << ").";
}
return(0)
}
Explanation / Answer
few brackets and << are missing
#include <iostream>
using namespace std;
int main()
{
double x1; // x1 coord
double x2; // x2 coord
double y1; // y1 coord
double y2; // y2 coord
cout <<"Enter x1 and y1 (2 points) "; // promt user for x1 and y1
cin >> x1; // cord x1
cin >> y1; // cord y1
cout <<"Enter x2 and y2 (2 points) "; // promt user for x2 and y2
cin >> x2; // cord of x2
cin >> y2; //coord of y2
if ( x1 == x2 && y1 == y2) {
cout <<"Point (" << x2 << "," << y2 << ") equals point (" << x1 << "," << y1 << ").";
} else if( x1 < x2 && y1 == y2) {
cout <<"Point (" << x2 << "," << y2 << ") is the right of point (" << x1 << "," << y1 << ").";
}
else if ( x1 > x2 && y1 == y2 ) {
cout << "Point (" << x2 << "," << y2 << ") is the left of point (" << x1 << "," << y1 <<")).";
}
else if ( x1 == x2 && y1 < y2) {
cout <<"Point (" << x2 << "," << y2 << ") is above the point (" << x1 << "," << y1 <<").";
}
else if (x1 == x2 && y1 > y2) {
cout <<"Point (" << x2 << "," << y2 << ") is below the point (" << x1 << "," << y1 <<").";
}
else if (x1 > x2 && y1 < y2 ) {
cout <<"Point (" << x2 << "," << y2 << ") is above and left of the point (" << x1 << "," << y1 << ").";
}
else if (x1 < x2 && y1 < y2 ) {
cout <<"Point (" << x2 << "," << y2 << ") is above and right of the point (" << x1 << "," << y1 << ").";
}
else if (x1 < x2 && y1 > y2 ) {
cout <<"Point (" << x2 << "," << y2 << ") is below and right of the point (" << x1 << "," << y1 << ").";
}
else if (x1 > x2 && y1 > y2 ) {
cout <<"Point (" << x2 << "," << y2 << ") is below and left theh point (" << x1 << "," << y1 << ").";
}
return(0);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.