Development Pascal help!!!!!

Discussion in 'Software' started by Fly, 9 Feb 2003.

  1. Fly

    Fly inter arma silent leges

    Joined:
    31 Aug 2001
    Posts:
    3,763
    Likes Received:
    3
    I'm trying to make a little program and I am having problems with a procedure that loops once for no apparent reason...

    run the program and see what I mean (select option 3)

    here's the code, ignore all except the procedure called game...
     
  2. Fly

    Fly inter arma silent leges

    Joined:
    31 Aug 2001
    Posts:
    3,763
    Likes Received:
    3
    and heres the executable
     
  3. Fly

    Fly inter arma silent leges

    Joined:
    31 Aug 2001
    Posts:
    3,763
    Likes Received:
    3
    Basically, when you select 3 in the main menu it is supposed to tell u what the range of colours is and how many, then ask for a user input, then, when you press return, call a function (which i have not coded yet) to check syntax. As you see when u run it, the function is called straight away and the guesscount is upped by one...


    I'm confused!!!!

    heeeeeelp!!!!

    :sigh:
     
  4. linear

    linear Minimodder

    Joined:
    5 Oct 2001
    Posts:
    4,393
    Likes Received:
    1
    Damn it's been over 10 years since I looked at Pascal code, so excuse any dust...

    Your saying that your do .. until() loop is exiting after one pass, and that looks correct given the code.

    the termination condition is (guess_result = false), and you se guess _result equal to the return value from guess_check(), which in your definition always returns false.

    So what you describe is exactly what I'd expect, if my Pascal parsing skillz are still okay after lo these many years.

    If you want the loop to execute more than once, you'll have to arrange for guess_check() to return true occasionally. :D
     
  5. Fly

    Fly inter arma silent leges

    Joined:
    31 Aug 2001
    Posts:
    3,763
    Likes Received:
    3
    repeat
    write ('Please enter your guess>');
    readln (dummy) {test dummy line}
    readln ( guess );
    guess_result := guess_check (guess);
    until guess_result = false;


    that's what is giving me the issue...

    It seems to run twice whenever I call procedure game

    I have even put a dummy readln there to test my theory and it automatically fills "dummy" with nothing and continues to the next read line. the thing is, next time it loops it calls for "dummy" and "guess".



    :sigh:
     
  6. relix

    relix Minimodder

    Joined:
    14 Nov 2001
    Posts:
    5,948
    Likes Received:
    41
    Don't have time atm to check the code, but I just want to slap your fingers for typing something like "guess_result = false"!!


    *slap*


    there, here's the last code rewritten for you:

    repeat
    write ('Please enter your guess>');
    readln (dummy) {test dummy line}
    readln ( guess );
    guess_result := guess_check (guess);
    until not guess_result;


    well, I can't blame ya, I've done it way too many times myself, also something I did lots was "until guess_result = true", which can be replaced by "until guess_result"... :D

    (I'll check the code tomorrow, now need sleep :p)
     
  7. linear

    linear Minimodder

    Joined:
    5 Oct 2001
    Posts:
    4,393
    Likes Received:
    1
    Like I said it has been a long time--I blink whenver I see "if(foo=bar)" in any form because in C it's a legitimate construct that probably doesn't mean what you think it does. I do know := is assignment in Pascal, but it's a habit thing....
     
  8. Fowler

    Fowler mmm Cosworth

    Joined:
    20 Nov 2002
    Posts:
    1,297
    Likes Received:
    0
    Use the debugger, add break points and watches if u need them!
    Turbo debugger is ur friend!
     

Share This Page