Thread: New Programer

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    9

    New Programer

    Hi.
    I am a new programer in C an C++. Actually, I know some basic things and I am trying to write a program in C++ using one in C. So I would like someone to tell me the meaning of the comand

    SIGN(h1,x2-x1);

    which I need to replace for one in C++.

    Thank you very much!

  2. #2
    Registered User Micko's Avatar
    Join Date
    Nov 2003
    Posts
    715
    It seems that SIGN is some kind of macro. Does that your code have line that begins with #define SIGN...?
    Gotta love the "please fix this for me, but I'm not going to tell you which functions we're allowed to use" posts.
    It's like teaching people to walk by first breaking their legs - muppet teachers! - Salem

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    9
    Micko,

    Thank for your help.
    I have not that line in the code. I think I should have it.
    So I have found a kind of definition of SIGN in another program which is called from the one I am using:

    #define SIGN(a,b) ((b) >= 0.0 ? fabs(a) : -fabs(a))

    I will add this line...

  4. #4
    Registered User Micko's Avatar
    Join Date
    Nov 2003
    Posts
    715
    I'm glad I helped, but I'm curious about this.
    Usually, sign function in math (often labeled as sgn) takes only one argumet and return +1 or -1 depending of sign of the argument. See http://mathworld.wolfram.com/Sign.html
    Using name "SIGN" can be misleading...
    Gotta love the "please fix this for me, but I'm not going to tell you which functions we're allowed to use" posts.
    It's like teaching people to walk by first breaking their legs - muppet teachers! - Salem

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    9
    I see. It is interesting...
    I have to check what my code is doing with this SIGN definition.
    Thanks again.

  6. #6
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Code:
    z=SIGN(h1,x2-x1)
    would become
    Code:
    if ((x2-x1) >=0) z=fabs(h1)
    else z=-fabs(h1)
    I think, or something silimar!!!

  7. #7
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    You could pass the program through the preprocessor (without compiling it) and see what SIGN expands to. Eg. the GCC allows you to access the preprocessor as a seperate "cpp" executable.
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. new programer help
    By kiwiking in forum C++ Programming
    Replies: 5
    Last Post: 04-19-2008, 11:38 PM
  2. Replies: 2
    Last Post: 10-23-2004, 03:46 AM
  3. Newbie C Programer Needs Help ASAP
    By Halo in forum C Programming
    Replies: 4
    Last Post: 02-21-2002, 01:52 AM