im very new to c++ and having a hard time doing this question if anyone could help me with me that be awesome!
Write a complete C++ program that prompts the user for the x and y coordinates of two Cartesian points, then calculates and displays the distance between them. Assume that the coordinate values are whole numbers. The distance between two points having the coordinates (x1, y1) and (x2, y2) is distance = the square root of ([x1 - x2]2 + [y1 - y2]2 ).
struct coordinates // structure for coordinates
{
int x;
int y;
}point1, point2; // two points x1,y1 & x2,y2
void read(coordinates &pt) // function to read values
{
cout<<"Enter the value for x coordinate";
cin>>pt.x;
cout<<"Enter the value for y coordinate";
cin>>pt.y;
}
void main()
{
clrscr();
float distance;
read(point1);
read(point2);
distance=sqrt(((x1 - x2)*(x1 - x2)) + ((y1 - y2)*(y1 - y2)));
cout<<" Distance between the two coordinates is"<<distance;
getch();
}
int main() ALWAYS int main(), the reason for this is so that the command shell gets a pass\fail result from the application when it is done executing. void main() returns nothing to what called it.
lol why thank you i thought i give a highfive...this is my first time ever doing C++ so some may think its so0o easy and like me may take awhile but you learn something everyday which is good :)..it was just one of those things i kept starring at and missed but its cool :)
void main() does actually return a value to the command shell but it returns an indeterminate garbage value which is actually worse than nothing since it may fool the shell into thinking that the code failed when it really didn't. If code you write returns random errors once or twice every 10,000 times it runs you will have some very tricky debugging to do.
C and C++ standards both explicitly prohibit void main(), ignore them at your own risk.