[Info-vax] ChatGPT solved it for me, again...

Slo slovuj at gmail.com
Fri Feb 17 09:54:40 EST 2023


Let's see how well it survives the round trip:
Me: Convert this C code to Pascal
==================================
Here's the Pascal equivalent of the provided C code:
program power_supply_compatibility;
uses sysutils;
var
  sys1, sys2: string;
  watt1, watt2: integer;
function get_wattage(sys: string): integer;
begin
  Randomize;
  get_wattage := (Random(32767) mod 20) * 50 + 200;
end;
begin
  WriteLn('Utility to check power supply compatibility.');
  Write('Enter name of system #1: ');
  ReadLn(sys1);
  Write('Enter name of system #2: ');
  ReadLn(sys2);
  watt1 := get_wattage(sys1);
  watt2 := get_wattage(sys2);
  if watt1 = watt2 then
    WriteLn(sys1, ' and ', sys2, ' can use the same power supply (', watt1, ' watt)')
  else
    WriteLn(sys1, ' and ', sys2, ' cannot use the same power supply as they use ', watt1, ' and ', watt2, ' watt');
end.

Notes:
The main differences between the C code and the Pascal code are:
    In Pascal, the uses keyword is used to import the sysutils unit, which includes the Randomize function.
    In Pascal, the Randomize function is used to initialize the random number generator.
    In Pascal, the ReadLn function is used to read input from the user.
    In Pascal, the WriteLn procedure is used to output text to the user.
    In Pascal, the mod operator is used to compute the remainder of a division.
==================================



More information about the Info-vax mailing list