There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 bios blue screen boot browser bsod computer connection cpu crash css dell desktop driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware hijackthis hjt install internet internet explorer itunes keyboard laptop macro malware monitor network networking outlook outlook 2003 outlook 2007 outlook express password popups problem problems router seo server slow sound sp3 spyware trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
C++ helpppp


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
RubberDucky1's Avatar
Junior Member with 3 posts.
 
Join Date: Dec 2002
12-Dec-2002, 03:19 PM #1
C++ helpppp
I am trying to make a program that calculates the distance formula.. this is what i have right now..

#include<iostream.h>
#include<math.h>
main()
{
double distance;
struct point{
int x;
int y;
};
point pt1, pt2;
cin>>pt1.x;
cin>>pt2.x;
cin>>pt1.y;
cin>>pt2.y;

distance = sqrt(pow((pt2.x-pt1.x),2)+(pow((pt2.y-pt1.y),2)));

cout<<distance<<endl;;

return 0;
}

can someone please help out and tell me what is wrong.

thx,

RubberDucky
Guy's Avatar
Guy Guy is offline
Senior Member with 260 posts.
 
Join Date: Feb 1999
Location: abby, BC, canada
12-Dec-2002, 06:35 PM #2
What is not working about it? what are the headers you include? By "distance formula", I assume you mean the distance between the two points.

Here is a quick example that works for me:

Code:
#include &lt;iostream&gt;
#include &lt;cmath&gt;
struct point
{
	int x, y;
};

using namespace std;
int main(int argc, char* argv[])
{
	point a, b;
	cin&gt;&gt;a.x&gt;&gt;a.y&gt;&gt;b.x&gt;&gt;b.y;
	double distance = sqrt(pow((b.x-a.x), 2) + pow((b.y-a.y), 2));
	cout&lt;&lt;"Distance between: "&lt;&lt;distance&lt;&lt;endl;
	return 0;
}
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 11:42 PM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.