[newbie question] need help programming in c++

Discussion in 'Computer Support' started by Phate, Oct 1, 2003.

  1. Phate

    Phate Guest

    hi, i am trying to find the perimeter and area of a quadrilateral but
    something is seriously wrong with the area portion of my code, this is my
    program so far:

    #include <iostream.h>
    #include <math.h>

    int main()
    {
    double x1, x2, x3, x4, y1, y2, y3, y4, d1, d2, d3, d4, td, s, a, h, b;

    cout<<"This program will find the perimeter and area of a
    quadrilateral.\n";
    cout<<"Please enter your first 'x' value: ";
    cin>>x1;
    cout<<"Please enter your first 'y' value: ";
    cin>>y1;
    cout<<"Please enter your second 'x' value: ";
    cin>>x2;
    cout<<"Please enter your second 'y' value: ";
    cin>>y2;
    cout<<"Please enter your third 'x' value: ";
    cin>>x3;
    cout<<"Please enter your third 'y' value: ";
    cin>>y3;
    cout<<"Please enter your fourth 'x' value: ";
    cin>>x4;
    cout<<"Please enter your fourth 'y' value: ";
    cin>>y4;
    d1=sqrt(((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)));
    d2=sqrt(((x2-x3)*(x2-x3))+((y2-y3)*(y2-y3)));
    d3=sqrt(((x3-x4)*(x3-x4))+((y3-y4)*(y3-y4)));
    d4=sqrt(((x4-x1)*(x4-x1))+((y4-y1)*(y4-y1)));
    td=d1+d2+d3+d4;
    cout<<"The perimeter of your quadrilateral is: "<<td<<"m.\n";
    b=sqrt(((x1-x3)*(x1-x3))+((y1-y3)*(y1-y3)));
    s=(d1+d2+b)/2;
    h=sqrt((s)*(s-d1)*(s-d2)*(s-b)); //heron
    formula
    a=((.5)*b*h)/10;
    cout<<"The area of your quadrilateral is: "<<a<<"m^2.\n";
    return 0;
    }
     
    Phate, Oct 1, 2003
    #1
    1. Advertisements

  2. Phate

    why? Guest

    These are questions for you to work on by yourself, if you want to reply
    fine.

    So your input is? Which gives what answer? If you do the calculation by
    hand following the method below you get what?

    Use cout to display intermediate results, do they match the traditional
    manual calculation at each step?

    .... education now days... sheesh....
    <snip>

    Me
     
    why?, Oct 1, 2003
    #2
    1. Advertisements

  3. We all know that Phate screamed at the top of his lungs:
    just do this in your head or on paper: P=(2A)+(2B)
    |---------|
    a | |
    |--------- |
    B
    --

    Do the Dew - Dewman
    has been changed to
    We all Live in a "Yellow Submarine"

    DUH
     
    yellow submarine, Oct 1, 2003
    #3
  4. Phate

    °Mike° Guest

    °Mike°, Oct 1, 2003
    #4
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.