• Status: Solved
• Priority: Medium
• Security: Public
• Views: 543

# 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.
0
kazooie21
• 3
1 Solution

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

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

## Featured Post

• 3
Tackle projects and never again get stuck behind a technical roadblock.