Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

c++ whats wrong with this program?

#include <iostream>

#include <iomanip>

#include <cmath>

using namespace std;

struct Point

{

int x;

int y;

};

struct Triangle

{

Point pointA;

Point pointB;

Point pointC;

};

double distance(Point, Point);

int main()

{

const int NUM_TRIANGLES = 3;

Triangle members[NUM_TRIANGLES];

for (int index = 0; index < NUM_TRIANGLES; index++)

{

cout << "Enter x and y coordinates for point A in triangle " << (index + 1) << ": ";

cin >> members[index].pointA.x >> members[index].pointA.y;

cout << "Enter x and y coordinates for point B in triangle " << (index + 1) << ": ";

cin >> members[index].pointB.x >> members[index].pointB.y;

cout << "Enter x and y coordinates for point C in triangle " << (index + 1) << ": ";

cin >> members[index].pointC.x >> members[index].pointC.y;

}

for (int index = 0; index < NUM_TRIANGLES; index++)

{

double A = distance(members[index].pointA, members[index].pointB);

double B = distance(members[index].pointB, members[index].pointC);

double C = distance(members[index].pointC, members[index].pointA);

double perimeter = A + B + C;

cout << "Perimeter of Triangle " << (index + 1) << ": ";

cout << fixed << showpoint << setprecision(2) << perimeter;

cout << endl;

}

system("pause");

return 0;

}

double distance(Point point1, Point point2)

{

double x_diff = point2.x - point1.

double y_diff = point2.y

double side = sqrt(pow(x_diff, 2.0) + pow(y_diff, 2.0));

return side;

}

Update:

the double x_diff = point2.x - point1.x

the double y_diff = point2.y - point1.y

4 Answers

Relevance
  • 7 years ago

    Instead of putting std::cout everywhere you need it, you could just use: using std::cout; in place of using namespace std;. And you could use a separate using directive on a separate line for each case, like:

    using std::cin;

    using std::cout;

    using std::whatever;

  • Anonymous
    7 years ago

    your compiler is confusing your distance formula with the distance function of the iterator

    http://www.cplusplus.com/reference/iterator/distan...

    http://www.cplusplus.com/reference/iterator/

    you have

    using namespace std;

    and distance is part of std

    so that's the one it uses

    I'm not entirely sure why

    I didn't look at it that closely

    anyway, you should comment out the

    using namespace std;

    and put

    std::cout

    everywhere you need it

    and fix it everywhere else too

    its actually considered bad practice to do

    using namespace any_nameapce;

    you should always use the prefix method

    for this particular reason

    oh, next time put your code in pastebin.com

    it makes it so much easier to read

  • Anonymous
    7 years ago

    u have no life this is your problem seek help.

    immediately.

  • 7 years ago

    Can you at least tell us what is wrong?

Still have questions? Get your answers by asking now.