New to Pascal - Trying to do some basic stuff

So I'm new at learning at Pascal, and I'm just trying to make a simple circumference program. This is what I have:

[code]
program Circumference;

const
pi = 3.14159265;

var
radius : integer;
circumference : real;

begin
write ('What is the radius of the circle? ');
readln (radius);
circumference := 2 * pi * radius;
writeln ('The circumference is:' circumference);
readln;
end.
[/code]
But it doesn't work, any tips?

Comments

  • : So I'm new at learning at Pascal, and I'm just trying to make a
    : simple circumference program. This is what I have:
    :
    : [code]:
    : program Circumference;
    :
    : const
    : pi = 3.14159265;
    :
    : var
    : radius : integer;
    : circumference : real;
    :
    : begin
    : write ('What is the radius of the circle? ');
    : readln (radius);
    : circumference := 2 * pi * radius;
    : writeln ('The circumference is:' circumference);
    : readln;
    : end.
    : [/code]:
    : But it doesn't work, any tips?
    :
    First, the variable [b]circumference[/b] is a dupe of the program name. That's not allowed.
    Second, you need a comma after the string in the writeln statement.
    Third, why is radius an integer? It works, but only if you enter an integer. If you enter a real (with a decimal point) you get a run-time error.
    Fourth, your output will be in scientific notation. Is this what you want?
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion