Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

New to Pascal, please help

JoshellJoshell Posts: 3Member
I have recently started learning Pascal and I am having difficulties compiling what should be a simple program. It is a program to compute the volume of a sphere when given a radius. Below I will give the errors when compiling and then my code. I also have remarked the lines where the errors are given. If someone can help me with this I would greatly appreciate it.

Errors:

volume.pas(13,1) Error: Duplicate identifier VOLUME
volume.pas(13,1) Hint: Identifier already defined in volume.pas at line 5
volume.pas(13,1) Error: Duplicate identifier VOLUME
volume.pas(13,1) Hint: Identifier already defined in volume.pas at line 5
volume.pas(19,9) Fatal: Syntax error, . expected but := found

Code:

program volume;

(* given radius, compute volume of a sphere *)

const (* line 5 *)
PI = 3.141593;

var
Radius,
Volume: real;


begin (* line 13 *)

writeln;
write('What is the radius of the sphere? ');
readln(Radius);

Volume := (4.0 / 3.0) * (PI * (sqr(Radius) * Radius)); (* line 19* )

writeln;
writeln('The volume of the sphere is: ', Volume);
writeln

end.

Comments

  • ManningManning Posts: 1,621Member
    : I have recently started learning Pascal and I am having difficulties compiling what should be a simple program. It is a program to compute the volume of a sphere when given a radius. Below I will give the errors when compiling and then my code. I also have remarked the lines where the errors are given. If someone can help me with this I would greatly appreciate it.

    The problem is that whatever you call your program becomes a reserved word. In this case you are calling you program "Volume", which means that is now an invalid variable name.

    Because of this I usually prefix program names with an _ or something. If you make a change like that it should compile fine.
  • JoshellJoshell Posts: 3Member
    : : I have recently started learning Pascal and I am having difficulties compiling what should be a simple program. It is a program to compute the volume of a sphere when given a radius. Below I will give the errors when compiling and then my code. I also have remarked the lines where the errors are given. If someone can help me with this I would greatly appreciate it.
    :
    : The problem is that whatever you call your program becomes a reserved word. In this case you are calling you program "Volume", which means that is now an invalid variable name.
    :
    : Because of this I usually prefix program names with an _ or something. If you make a change like that it should compile fine.
    :

    Thank you very much for you help. I changed the program name and now it compiles correctly. I've been pulling my hair out trying to figure what the "duplicate" identifier was.
  • viv.viv. Posts: 72Member
    : Errors:
    :
    : volume.pas(13,1) Error: Duplicate identifier VOLUME
    - this means that u used the volume for two things, u did it in PROGRAM volume; and in your VAR heading.

    : volume.pas(13,1) Hint: Identifier already defined in volume.pas at line 5
    -same

Sign In or Register to comment.