How do I?? Please Read this!!!!


I think I have pretty much finished my source code for my second assignment. It is a menu driven program. I need a little help with one thing.

In module #2 the user is to type in a number.

If the user does not type in a number the program stops.

I need to constuct a invalid portion and I am not sure what I am doing wrong .

This is what I am typing in

program Primenumber;

uses crt;


n, trialdiv : integer;

prime : boolean;



write ('enter a number:');

readln (n);

If (n < integer) THEN


writeln('You have not selected a number');

writeln('Please try again');


this comes out as expected "(" at the THEN

Please if anyone can look this this over it would be great as it is due this afternoon.


Thank you very much


  • Try reading in a string and then test whether the string is an integer

  • : Try reading in a string and then test whether the string is an integer



    Thank you for replying.

    If I am reading in a string what would I do different in my readln.

    writeln('type in a number');


    would it be that I would declare the variable (n) as a string instead of a integer?

    And how would I test a string to see if it is a integer?

    Thanks again


  • You can declare N as a string type.

    Note that there is a pascal function called "val" which converts a string type to its numeric value. The function is something like this

    val(str : string, var int, code : integer);

    the code returns zero if the operation is successful, so maybe you can do something like this:


    N : string;

    number, code : integer;


    writeln('Enter a number');


    val(N, number, code);

    if code <> 0 then writeln('Invalid integer')

    else writeln('You have entered an integer');


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!