Pascal to C++ 2 functions

This is a discussion on Pascal to C++ 2 functions within the C++ Programming forums, part of the General Programming Boards category; all right Iím trying to convert this Pascal code to C++ witch i can do i just need help with ...

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    43

    Pascal to C++ 2 functions

    all right Iím trying to convert this Pascal code to C++ witch i can do i just need help with 2 functions

    here is the Pascal code
    Code:
    //Returns the amount Of pixels between a1, b1 And a2, b2
    
    
    Function Dist(a1, b1, a2, b2 : Integer) : Integer;
    Var
      aa, bb : Extended;
    Begin
      If(a1>a2)Then
        aa:= (a1 - a2) * (a1 - a2)
      Else
        aa:= (a2 - a1) * (a2 - a1);
      If(b1>b2)Then
        bb:= (b1 - b2) * (b1 - b2)
      Else
        bb:= (b2 - b1) * (b2 - b1);
      result:= trunc(Sqrt(aa + bb)) + 1;
    End;
    ok now i need help with a trunc function in C++ what it does i believe is takes away the decimal point from any number.
    and the sqrt function witch is square root.
    Iím Dyslexic and I know that I donít spell well so quit telling to learn my English because I do my best at it all right.

    Windows XP with Dev-C++ for now.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,304
    ok now i need help with a trunc function in C++ what it does i believe is takes away the decimal point from any number.
    Casting to an integral type will result in truncation.

    and the sqrt function witch is square root.
    sqrt() is available in <cmath>
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,762
    > ok now i need help with a trunc function in C++ what it does i believe is takes away the decimal point from any number.
    Just cast it to an integral type such as int:

    result = 1 + static_cast< int >( sqrt( aa + bb ) );

    >and the sqrt function witch is square root.
    #include <cmath>
    std::sqrt( double n );

  4. #4
    Registered User
    Join Date
    Nov 2007
    Posts
    43
    thank you
    Iím Dyslexic and I know that I donít spell well so quit telling to learn my English because I do my best at it all right.

    Windows XP with Dev-C++ for now.

  5. #5
    Registered User
    Join Date
    Nov 2007
    Posts
    43
    also if you guys coud answer this one
    Code:
    if (GetAsyncKeyState(VK_ESCAPE))
    {
    exit(0);
    }
    Now if I press the ESC button the then the program should stop right. But it seams to stop even when I haven’t pressed the button.

    lol and thanks laserlight your always answering my posts I appreciate it.
    Iím Dyslexic and I know that I donít spell well so quit telling to learn my English because I do my best at it all right.

    Windows XP with Dev-C++ for now.

  6. #6
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Quote Originally Posted by MSDN
    If the function succeeds, the return value specifies whether the key was pressed since the last call to GetAsyncKeyState, and whether the key is currently up or down. If the most significant bit is set, the key is down, and if the least significant bit is set, the key was pressed after the previous call to GetAsyncKeyState. ....
    -->> it never retuns 0.
    Kurt

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Correct, you need to do an "and with 1" to see if the key was pressed or not.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  8. #8
    Registered User
    Join Date
    Nov 2007
    Posts
    43
    ok so the way i have it now it is returning true no matter what because it never returns 0
    can some one leave an example of how it shoud be frased. thanks for you help i see how it works now anyway : )
    Iím Dyslexic and I know that I donít spell well so quit telling to learn my English because I do my best at it all right.

    Windows XP with Dev-C++ for now.

  9. #9
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Code:
    if (GetAsyncKeyState(VK_ESCAPE) & 1)
    {
    exit(0);
    }
    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Void Functions Help
    By bethanne41 in forum C++ Programming
    Replies: 1
    Last Post: 05-09-2005, 06:30 PM
  2. Functions and Classes - What did I do wrong?
    By redmage in forum C++ Programming
    Replies: 5
    Last Post: 04-11-2005, 12:50 PM
  3. calling functions within functions
    By edd1986 in forum C Programming
    Replies: 3
    Last Post: 03-29-2005, 03:35 AM
  4. Factory Functions HOWTO
    By GuardianDevil in forum Windows Programming
    Replies: 1
    Last Post: 05-01-2004, 02:41 PM
  5. Shell functions on Win XP
    By geek@02 in forum Windows Programming
    Replies: 6
    Last Post: 04-19-2004, 06:39 AM

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