Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

FizzBuzz

program Fizzbuzz;
//Jonas Yip
uses Math,StrUtils;
var Max_Number,i,Base_1,Base_2 : integer;
    Boo_Fizz,Boo_Buzz,Boo_FizzBuzz,Output,Index : string; //Boo - Boolean
procedure Start;
begin
  write('Maxinmum Number | Base 1 | Base 2 // i.e 10 2 3 ');
  try
     readln(Max_Number,Base_1,Base_2);
  except try
         Start;
  finally end;
  end; //Validation end
  for i:=1 to Max_Number do //Loop!
    begin
      Str(i,Index); //Change i into a string
      //[Note] Declaring datatypes in the ternary condition operators
      Boo_Fizz := IfThen((i mod Base_1) = 0, 'Fizz', Index); //Ternary operator
      Boo_Buzz := IfThen((i mod Base_2) = 0, 'Buzz', Index);
      Boo_FizzBuzz := IfThen(((i mod Base_1) = 0) and ((i mod Base_2) = 0), 'FizzBuzz', Index);
      Output := IfThen(Boo_Fizz = Boo_Buzz, Index, 'False'); //Pre assigned first
      if (Boo_FizzBuzz = 'FizzBuzz') then
         Output := Boo_FizzBuzz //Check first
      else if (Boo_Buzz = 'Buzz') then
         Output := Boo_Buzz
      else if (Boo_Fizz = 'Fizz') then
         Output := Boo_Fizz; //Last statement
      writeln(Output);
    end;
  Start;
end;
begin
  Start;
  readln;
end.

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.