Link to home
Start Free TrialLog in
Avatar of kazooie21
kazooie21

asked on

program for a Fahrenheit and Celsius table

I need a program that will print a table for Fahrenheit and Celsius. It should look something like this:
 
 Fahrenheit       Celsius
        32


The numbers in the Fahrenheit are aligned starting with the "i" in Fahrenheit. The numbers in the Celsius are aligned starting with the "i" in Celsius.

The program should convert Fahrenheit to Celsius using this formula:
Celsius = (Fahr - 32) * 5/9)
The numbers in the Fahrenheit column are incremented by two.
I believe this should be in the form of a While loop. Here's what I have so far:

var celsius: real;
fahr := 32;
    while fahr < 100 do
      begin {begin while loop}
       celsius := (fahr - 32) * 5/9);
         writeln (fahr, ' ' , celsius)
           fahr := fahr + 2
      end;{end while loop}
    end.
ASKER CERTIFIED SOLUTION
Avatar of lama72phl
lama72phl

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dbrunton
Your code seems ok.  The only problem is ouputting.  Try this in your code.

writeln('Fahrenheit, '     ', Celsius'); {* five spaces between Fahrenheit and Celsius *}
writeln;



write(fahr:9);
writeln(celsius:11:0);

lama72phl's code is probably correct but he does not state how he is writing the line 'Fahrenheit     Celsius'

If he did he probably has the right answer.
Avatar of lama72phl
lama72phl

their is only one space between 'fahrenheit' and 'celcius' in the
line:  writeln('fahrenheit celcius');
their is only one space between 'fahrenheit' and 'celcius' in the line:

  writeln('fahrenheit celcius');

also one space in:

   writeln(fahrenheit:9,' ',celcius:6:2);
This is a nicer way to do a cycle incrementing control variable by two:

For count:=0 to 100 do begin...
     ...
     Inc(count);
end;

At each turn, Count is incremented twice: once by the Inc() procedure and once again by the For instruction itself.

Yes; that's a clear example of what NOT to be done. But it's clear, brief, and nice (and the most important: it works :)

A good comment will fix the problem of obscureness.