Thread: Turbo C++ vs Visual C++ , weird!!

  1. #1
    Unregistered
    Guest

    Exclamation Turbo C++ vs Visual C++ , weird!!

    Hello everyone......

    I had my practical C++ final exam today, I hope I did well......

    The question was to write a program and a function to read the sides of 5 triangles and determine whether they are proper or improper. Here is the code -I know, I should have used a loop-:

    -----------------------------------------------------------------------------------

    #include <iostream.h>
    #include <fstream.h>

    int triangle (int , int , int); //prototype
    int main()
    {
    int triangle1a,triangle1b,triangle1c,
    triangle2a,triangle2b,triangle2c,
    triangle3a,triangle3b,triangle3c,
    triangle4a,triangle4b,triangle4c,
    triangle5a,triangle5b,triangle5c,
    answer;

    ifstream infile ("input.txt" , ios::in); //specifies file to read from

    infile>>triangle1a>>triangle1b>>triangle1c;
    answer = triangle (triangle1a,triangle1b,triangle1c);
    if (answer == 0)
    cout<<"Triangle number 1 is not proper"<<endl;
    else cout<<"Triangle number 1 is proper"<<endl;


    infile>>triangle2a>>triangle2b>>triangle2c;
    answer = triangle (triangle2a,triangle2b,triangle2c);
    if (answer == 0)
    cout<<"Triangle number 2 is not proper"<<endl;
    else cout<<"Triangle number 2 is proper"<<endl;


    infile>>triangle3a>>triangle3b>>triangle3c;
    answer = triangle (triangle3a,triangle3b,triangle3c);

    if (answer == 0)
    cout<<"Triangle number 3 is not proper"<<endl;
    else cout<<"Triangle number 3 is proper"<<endl;

    infile>>triangle4a>>triangle4b>>triangle4c;
    answer = triangle (triangle4a,triangle4b,triangle4c);

    if (answer == 0)
    cout<<"Triangle number 4 is not proper"<<endl;
    else cout<<"Triangle number 4 is proper"<<endl;

    infile>>triangle5a>>triangle5b>>triangle5c;
    answer = triangle (triangle5a,triangle5b,triangle5c);

    if (answer == 0)
    cout<<"Triangle number 5 is not proper"<<endl;
    else cout<<"Triangle number 5 is proper"<<endl;

    return 0;


    }

    int triangle (int A ,int B , int C) //definition of function triangle
    {
    int Answer;


    if (A<B+C && B<A+C && C<A+B)
    Answer = 1;

    else Answer =0 ;


    return Answer;

    }


    ------------------------------------------------------------------------------------
    And the input values were :

    5 3 1
    3 4 5
    7 9 10
    6 14 8
    2 7 3

    ------------------------------------------------------------------------------------

    And the output should be:

    Triangle number 1 is not proper
    Triangle number 2 is proper
    Triangle number 3 is proper
    Triangle number 4 is not proper
    Triangle number 5 is not proper

    ------------------------------------------------------------------------------------

    The weird thing is that in college I typed-in and compiled the code using Turbo C++, and when I executed it I got totally different answers, and I kept getting different ones each time I executed the program. So I copied the code on a disk, took it home, and compiled it using microsoft visual c++ 6, this time I got the same answers above everytime I executed the program. Could the college computer somehow "messed up"? or was it the compiler?

    Thank you

  2. #2
    Registered User Kuplex's Avatar
    Join Date
    Dec 2001
    Posts
    18

    Question Maybe this?

    if (A<B+C && B<A+C && C<A+B)

    maybe if you rewrote it as:

    if ((A<(B+C)) && (B<(A+C)) && (C<(A+B)))

    i dont knwo if that will change anything though, unless turbo C++ doesn't recognize an order of operations or something
    Kuplex
    "The only thing you can count on is uncertainty."

    Must I explain myself futher?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  2. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  3. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  4. Errors with including winsock 2 lib
    By gamingdl'er in forum C++ Programming
    Replies: 3
    Last Post: 12-05-2005, 08:13 PM
  5. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM