# 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.
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
I have assumed you'll be using only up to 2 decimal places.  Here's the code and i hope it helps.

uses crt;
var celcius:real;
fahrenheit:integer;{no use in declaring fahr. as real since you're                                       counting ordinal values, anyway}
count:byte;
begin
writeln('fahrenheit celcius');
count:=0;
repeat
fahrenheit:=count;
celcius:=(fahrenheit-32)*(5/9);
writeln(fahrenheit:9,' ',celcius:6:2);
inc(count,2);
until count>100;
end.
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Commented:
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.
0
Commented:
their is only one space between 'fahrenheit' and 'celcius' in the
line:  writeln('fahrenheit celcius');
0
Commented:
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);
0
Commented:
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.

0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Pascal

From novice to tech pro — start learning today.