Results 1 to 6 of 6

Thread: Would anyone mind checking this?

  1. #1

    Would anyone mind checking this?

    Hi Guys,

    Assignment 2...

    idead being a different word is returned if integer is divisible by 3,5 or 15.
    I've used 'whitespaces' in the write ln for spacing.

    UNsure if this is the best method.

    Would anyone mind giving it the once over and checking for any errors?

    Thanks - the program does work as intended and displays ok, just a confirmation is what I'm after.

    Thanks again.

    Code:
    program BUZZFIZZ(output);
    
    uses    crt;
    
    const   columncount = 5;  {5 columns as 100 is div perfectly by 5}
            columnwidth = 15; {either needs whitespaces or set in writeln}
            Title: string = ('                               BUZZ FIZZ          ');
            By: string =    ('                             By Steve Green     ');
    
    var     i,j: integer;
            ch: char;
    
            begin {main program}
            ClrScr;
            writeln(Title);
            writeln;
            writeln(by);
            writeln;
    
            (* Hi, Welcome to etc etc, blaaaaaaaaaaaa, press return to*)
            readln(ch);
    
    
              for i := 1 to 9 do
               begin
                    if ((i mod 5) =j) then
                    write(i,'  = FIZZ       ')
                    else
                    if ((i mod 3) =j) then
                    write(i,'  = BUZZ       ')
                    else
                    write(i,'  =            ')
               end;
    
               for i := 10 to 100 do
                 begin
                   if ((i mod 15)=int) then
                   write(i,' = BUZZ FIZZ  ')
                   else
                   if ((i mod 5) =int) then
                   write(i,' = FIZZ       ')
                   else
                   if ((i mod 3) =int) then
                   write(i,' = BUZZ       ')
                   else
                   write(i,' =            ')
                end;
    
    
            writeln;
            writeln;
            writeln ('Press Return to continue',ch);
    
            read(ch);
            end.

  2. #2
    Code:
            Title: string = ('                               BUZZ FIZZ          ');
            By: string =    ('                             By Steve Green     ');
    You don't need the parentheses. Hence:

    Code:
            Title: string = '                               BUZZ FIZZ          ';
            By: string =    '                             By Steve Green     ';
    Next..

    You declare the variable "j", but never assign it a value; you are depending on the value of an uninitialized variable being 0, which is not a good idea. What reason are you using that variable? If it is just to compare to 0, then the code would be more meaningful if you just used 0.

    Similarly, you use the variable "int", which is neither declared nor initialized anywhere (the code as you pasted it shouldn't even compile), for the same reason. Again, if you just are comparing the result of the mod operation to zero, just use 0. Hence:

    Code:
                    if ((i mod 5) = 0) then
                    write(i,'  = FIZZ       ')
                    else
                    if ((i mod 3) = 0) then
    ...
                   if ((i mod 15) = 0) then
                   write(i,' = BUZZ FIZZ  ')
                   else
                   if ((i mod 5) = 0) then
                   write(i,' = FIZZ       ')
                   else
                   if ((i mod 3) = 0) then
    Lastly,

    Code:
            writeln ('Press Return to continue',ch);
    I pointed this out in the previous thread. There is no need to output the dummy input variable you are using to pause output. This will work fine:

    Code:
            writeln ('Press Return to continue');

  3. #3
    Hi,

    Cheers for taking the time to look at it. Seems it takes some time before the threads are posted here? Since that variant of it changes were made, I was over complicating it. In the end I think the code was quite simple. Or 'cleaner' anyway. (both int and j were remainder from my earlier prog as i was amending that one instead of writing from fresh)

    the "press ret to cont" bit, I tried it as you said and it wouldn't compile, so i've reverted to adding the 'ch' again.
    I don't understand why it doesn't work.

    [IMG]file:///C:/Users/steve/AppData/Local/Temp/moz-screenshot-5.png[/IMG]

  4. #4
    If it doesn't compile, it usually gives information on why it doesn't. writeln ('Press Return to continue',ch); makes no logic sense at all. You are basically printing a undefined char variable after the word 'continue'.

    Also, you can't link images from your local computer, they gotta be made either attachments to post or uploaded on a image hosting site.

  5. #5
    OK, It annoys me that soimethign that obvious wasn't picked up on by the lecturer...You guys have so far given me far more help and feedback than I've received in class. For that, thanks!

    Aha! Magic I had ch assisgned as a var char and I guess that was the issue, when I removed that and amended the final line to "readln()" it worked fine!
    also good to know i don't need brackets around the title strings, makes it cleaner and thats what I want.

    Would you recommend lazarus at all?

  6. #6

    the code

    here's the code for scrutiny

    Code:
    for i := 1 to 100 do
               begin
                  if (i mod 15=0) then
                  write('BUZZ FIZZ':10)
                  else
                  if (i mod 5=0) then
                  write('FIZZ':10)
                  else
                  if (i mod 3=0) then
                  write('BUZZ':10)
                  else
                  write(i:10)
                end;
            writeln;
            writeln;
            writeln ('Press <Return> to continue');
    
            readln();
                  end.

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
  •