c++ save me i need assistance

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 ).
#include<iostream.h>
#include<conio.h>
#include<math.h> // sqrt()

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();
}

Good Luck
thank u so much!! i had somewhat like that but i didnt add a void or a float distance no wonder lol thanks so muccccccccch!
void main()??? You should probably look this gift horse in the mouth if you want to get a good grade.
is that inncorrect? cause i never used a void main its usually a

int main {
}
so what is the correct answer?...i just tried mine and it won't work it keep saying i have all these errors but i cant pin point what is wrong :(
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.
so why when i try to complie my file it doesnt work and it keep showing errors?
You do realize that we can't see you right? What are the errors?
lol i no aha..i fixed it i just figured it out its one of those adding an extra bracket somewhere
Yeah those will always get you from time to time. It's good that you were able to spot and fix it on your own.
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.
GCC will actually refuse to compile something if it has void main(). Use int main() or int main(int argc, char * argv[]), but main must return an int.

Sorry.

-Albatross
ok thanks everyone :) great fed back ya i figured out what where i went wrong and now my code works hurray :)
Topic archived. No new replies allowed.