Results 1 to 10 of 25

Thread: Help / Advice please...

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

  2. #2
    I just had a play and it works fine, thankyou, this is also the first I've seen a procedure call upon another, something else that I've learnt, One thing though...Why have you added'()' at the end of them? Is this necessary? I've not used it on any of mine, is it better practice to have them?
    also...i just had an error message but what I'd now like it to do is store the pos / neg / zero boolean variables as a number. is this possible using these variables or should i have additional variables?
    thanks for taking the time to read /reply

  3. #3
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25
    The () is personal preference. They don't affect the compiled code what-so-ever only how your code is read. So honestly it would be up to you as how you prefer your own code-style to be. It's like that last semi-colon before the end in the main code block. You'll notice that he didn't add that either. I always add the semi-colon myself unless it's right before an else in an if .. than .. else statement.
    Jason McMillen
    Pascal Game Development
    Co-Founder





  4. #4
    PGD Staff code_glitch's Avatar
    Join Date
    Oct 2009
    Location
    UK (England, the bigger bit)
    Posts
    933
    Blog Entries
    45
    Hahaha, be careful there steven, you do not want to get into one of those style arguments... I always say indent 1 tab (set to 4 spaces in IDE), keep it all in line, break into blocks, add () whenever appropriate, same thing for ; add comments in blocks, separate it all out nicely and etc... If someone wants to read your code, then go ahead, just set tab to whatever spacing you like. Its sort of universal that way. Oh, and when passing variables to a procedure/function I prefer to do xyz(1, 2, y, h) instead of xyz(1,2,y,h) I just think it looks neater. Or you could abc( (cgdfd - uwergw), 8 ) with those spaces... its all about esthetics mainly. Compare it to ones taste in girls (talking bout you girls here so all girls officially banned from thread and no looking up my email address either ) - they are never the same so basically, no matter you're coding style: chances are, someone hates it. Now I'm not saying some people hate certain girls, but you get the picture. I might like (notice the MIGHT here) prefer thinner girls with a nice personality to the erm.... Models of our world. this is HYPOTHETICAL - don't make assumptions; female intuition does not solve the answer to everything. Its 42.
    I once tried to change the world. But they wouldn't give me the source code. Damned evil cunning.

  5. #5
    You need to drink less coffee, code_glitch

    Anyway, to answer your last question about the variables. You're definitely going to need different variables to store the totals. However, it's also possible to get rid of some. For example you use a variable to check the value read and then use that variable to display the outcome. Why not do both at the same time? It saves code and makes the whole thing easier to read.
    So instead of
    Code:
    pos:=numcheck>0;
    do this
    Code:
    if (numcheck > 0) then writeln('This is a positive number');
    Also, while I'm on the subject of variables. Try to have as few global variables as possible.
    Any variable that isn't needed outside of a procedure should be declared inside. ie
    Code:
    procedure askNumber();
    var numcheck : integer;
    begin
       ...

  6. #6
    ah, I see, thanks for clarifying. Code glitch - if you're not drinking obscene amounts of coffee then maybe you've got another substance taking it's toll As for woman...I know what you mean, not entirely sure I can compare my program to them, I like it to be perfect or as perfect as I know, doubt I'll ever find the perfect woman, thats a tall order but thanks for putting it in a way that any guy should understnads.

    traveller - I just read up on procedures some more, I'm going to play woth the code some more and put the var inside the proc, again, if it makes the code cleaner then I'm all for it. I like it when the prog is clean / tidy. thanks for pointing out the numcheck bit, it's things likethat that I don't notice striaght away. thanks. I'l post the next installment a bit later for your perusal.

    on the offchance...I'm puttign a website together (again this is an assignment that I wanted to take to the next level.) www.webdesignprofessionals.co.uk (any constructive criticism woudl be awesome.

  7. #7
    Hi guys,

    still having a couple of minor issues (by minor I mean...it's not working)

    I've got the same code as before, tidied it up a bit and put the var withing the procedures to make them local

    Code:
    program EX7NOSORT(input,output);
    uses    crt;
    var     posi,negi,zero:integer;
    
    heelo & press ret to cont proc
    
    procedure AskNumber;
    var numcheck:integer;
    begin
            writeln('What number/s would you like to check?');
            read(numcheck);
           begin---------------------added to test
            if  numcheck>0 then writeln('This is a positive number');
            read(posi);---------------------added to test
            if  numcheck<0 then writeln('This is a negative number');
            read(negi);---------------------added to test
            if  numcheck=0 then writeln('This number is Zero');
            read(zero);---------------------added to test
            end;
    end;
    
    procedure AskTotal;
    
    var count,totnum:integer;
    begin
            writeln;
            writeln('How many numbers will you like to check? ');
            readln(totnum);
    
            for count:= 0 to totnum-1 do AskNumber
    end;
    
    begin {main program}
           hello;
           AskTotal;
           writeln(posi);---------------------added to test
           cont;
                           {up to 33750}
    
    end.
    I tried several variations of read(posi) etc and write and i get nothing, the closest ic ame was when it displayed 3 zero's(when pos & neg were selected) I figure if I can get it to print one then I can work from there.
    It seems when I put the read lns in the code doesn't crash but i have to input several numbers and carriage returns before it asks the next number, then repeats until tot numbers has been reached.
    I'm a wee bit stuck, I thought by adding a begin / add it might separate the prog but no. I think I might have to ask chief(tutor) for help on this.
    It looked so easy to do as well! AGGGH!!!!!

  8. #8
    In pseudo code, you're now doing this.
    Code:
    Start program
    Ask user to input an amount of numbers
    loop over the given amount each time doing :
       1) ask for a number
       2) read the number into memory
       3) check if number is great than zero and write output to screen
       4) wait for user to input something
       5) check if number is below zero and write output to screen 
       6) wait for user to input something
       7) check if number is equal to zero and write output to screen  
       8) wait for user to input something  //end of loop
    write the value of posi to screen
    You should change this so that it looks more like this:
    Code:
    Start program
    initialize variables posi,negi,zero to 0
    Ask user to input an amount of numbers
    loop over the given amount each time doing :
       1) ask for a number
       2) read the number into memory
       3) check if number is great than zero. If this is true then 
                write output to screen
                save this instance to variable posi .
           if this is not true then
       4) check if number is below zero. If this is true then
               write output to screen 
               save this instance to a variable negi.
           if this is not true then
       5) check if number is equal to zero. If this is true then 
               write output to screen 
               save this instance to variable zero //end of loop
    write the value of posi, negi and zero to screen
    end program.

  9. #9
    PGD Staff code_glitch's Avatar
    Join Date
    Oct 2009
    Location
    UK (England, the bigger bit)
    Posts
    933
    Blog Entries
    45
    You need to drink less coffee
    Ah, what would life be without faithful ol' caffeine...

    Edit: oh, and gals of course
    Last edited by code_glitch; 26-03-2011 at 10:23 AM.
    I once tried to change the world. But they wouldn't give me the source code. Damned evil cunning.

  10. #10
    Hi guys,

    Thanks for point a few bits out there. You're right of course, It's hard enough learning the concept let alone the language as well, I'm also burrowing my head in php which is killing me. I handed the work i today, 15/15 for one and 14/15 for the other so not too bad at all. thankyou for all your help. No doubt i'll be posting again soon when I jump on the next mission - having to read / write to files and stuff now......yay..

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •