Newbie programmer, few quick questions...

This is a discussion on Newbie programmer, few quick questions... within the C++ Programming forums, part of the General Programming Boards category; I have just started learning C/C++. As practice i started doing a few challenge exercises. I am working on one ...

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    22

    Newbie programmer, few quick questions...

    I have just started learning C/C++. As practice i started doing a few challenge exercises. I am working on one such exercise in which i must write a program which can decide if three given points form an isosceles triangle (triangle with at least 2 congruent sides, for math illiterates). This is done by first making sure the points are not collinear (form a straight line) and then checking if the distance between any two points is the same. But i get a couple strange errors when compiling. I'm pretty sure the math is right. Anyway here is the code (d12 is distance between point 1 and 2, d13 = distance between point 1 and 3, you get it.):

    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
        int x1, y1, x2, y2, x3, y3, d12, d23, d13;
        bool is_collinear;
        is_collinear = 0;
        cout << "Enter x1";
        cin >> x1;
        cin.ignore();
        cout << "Enter y1";
        cin >> y1;
        cin.ignore();
        cout << "Enter x2";
        cin >> x2;
        cin.ignore();
        cout << "Enter y2";
        cin >> y2;
        cin.ignore();
        cout << "Enter x3";
        cin >> x3;
        cin.ignore();
        cout << "Enter y3";
        cin >> y3;
        cin.ignore();
        d12 = (((x1 - x2)^2) + ((y1 - y2)^2));
        d13 = (((x1 - x3)^2) + ((y1 - y3)^2));
        d23 = (((x2 - x3)^2) + ((y2 - y3)^2));
        if  ((y2 - y1) * (x3 - x1)) == ((y3 - y1) * (x2 - x1))
        {
            is_collinear = 1;
        }
        if ((is_collinear == 0) && ((d12 == d23) || (d12 == d13) || (d23 == d13)))
        {
            cout << "It is an isosceles triangle!";
        }
        else
        {
            cout << "It's not an isosceles triangle.";
        }
        cin.get();
    }
    when attempting to compile i get the following errors. Syntax error before '==' token on line 30 (first IF statement) and syntax error before '.' token on cin.get() function at global scope. I have no idea whats wrong. I have torn through many tutorials and as far as i can see there is nothing wrong with the code. What is wrong? BTW, i am using DevC++ 5. Thanx!

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,075
    Try this:
    Code:
    if  ((y2 - y1) * (x3 - x1) == (y3 - y1) * (x2 - x1))
    You had too many parenthesis.
    Sent from my iPadŽ

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. newbie questions
    By raptorx in forum C Programming
    Replies: 2
    Last Post: 10-10-2007, 10:30 PM
  2. Newbie Questions
    By snoopy1 in forum C++ Programming
    Replies: 3
    Last Post: 11-19-2006, 02:00 PM
  3. Im a newbie to C and i have some questions
    By pave1104 in forum C Programming
    Replies: 5
    Last Post: 07-05-2006, 10:48 PM
  4. 2 quick questions
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 11-29-2001, 12:32 AM
  5. A few quick questions...
    By cpp4ever in forum C++ Programming
    Replies: 3
    Last Post: 10-21-2001, 10:28 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21