Thread: Solving relationships...

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    84

    Solving relationships...

    Hi,
    I am working on a program and am wondering if someone can point me in the right direction with a certain concept.

    I would like my program to use a trial and error method of finding values for a series of variables which are related to one another by greater-than/less-than's in a series of predetermined rules.

    So my basic idea is that the program will randomly choose one of the variables to generate a random value for. It will then check the value of this variable against the other variables in terms of the greater-than/less-than rules, and if the value does not break any rules, it will keep that value and move onto generating a value for the next variable, etc.

    My first concern is that I need to be able to store null values for each variable's value until it is determined in the above sequence.
    Here is an example:
    Variable1 = 5
    Variable2 = NULL
    Variable3 = NULL

    Variable1 < Variable2 < Variable3

    GENERATE RANDOM VALUE FOR Variable2
    If Variable1 > Variable2, then regenerate Variable2.
    If Variable2 > Variable3, then regenerate Variable2.

    So, as you can see, Variable3 needs to be kept NULL here, rather than having a default value of zero or something.

    How do I go about this?
    Also, can anyone point me to some text that might discuss these types of programming issues.
    Thanks

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    My suggestion is to "know where you are". IOW: when generating variable2, you know variable3 hasn't been assigned yet, so don't even try checking it since it doesn't matter.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Having trouble solving maze.
    By eurus in forum C Programming
    Replies: 3
    Last Post: 02-17-2006, 01:52 AM
  2. JOB: C/C++ Developer with problem solving skills
    By VoltRecruiter in forum Projects and Job Recruitment
    Replies: 1
    Last Post: 01-26-2006, 12:25 AM
  3. Solving A Maze Using C Language!!!!
    By jonnybgood in forum C Programming
    Replies: 6
    Last Post: 11-08-2005, 12:15 PM
  4. Math: solving outcomes...
    By Oktos in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 04-10-2003, 06:55 AM
  5. Sign-up Thread: Problem Solving #1
    By ygfperson in forum Contests Board
    Replies: 15
    Last Post: 01-26-2003, 02:55 AM