I am very new to c++.After running the program It showed null error. It asks for both the inputs ie., x1,y1 and x2,y2. But when I press enter for output it returns to the coding screen.
#include<iostream.h>
#include<stdlib.h>
#include<math.h>
int main*(
{
system("cls");
double distance,x1,y1,x2,y2;
cout<<Enter coordinates (x y) for point1:";
cin>>x1>>y1;
cout<<Enter coordinates (x y) for point2:";
cin>>x2>>y2;
distance=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
cout<<"The distance between two points is <<distance<<endl;"
return 0;
}
@Daleth
Using std::flush with std::cout is really not necessary, std::cout already incorporate the std::flush method, so after every output with it, it automatically flushes the output stream.
@TheIdeasMan
From what I understand, std::flush only flushes the buffer while std::endl flushes and adds a newline character. In the line where I suggested using std::flush, one wouldn't need to add a newline character.