Search code examples
structrecordpascal

Why I get this skipping when I work with record 'struct' in pascal?


when i give him the number of item he skip the input of reference and designation and go directly to input of price as shown in the picture

when I give him the number of item he skip the input of reference and designation and go directly to input of price as shown in the picture

enter image description here


Solution

  • First, your image of the ouput doesn't comply with your code. The code until ((n>=3)... doesn't accept a "1" for entry, as your image suggests. Maybe you have changed the code after you made the image.

    Secondly, the reason for the program to run through all requests for user input is due to your usage of read() instead of readln().

    Read() reads all characters from the input buffer up to, but not including the CRLF produced by the Enter key. Read() leaves the CRLF characters in the buffer.

    ReadLn() reads all characters from the buffer, including the CRLF characters.

    When you call Read() after a previous call to Read(), the buffer still has the CRLF characters from the previous data entry, and there is no reason for the code to wait for those characters, so it just rumbles on with next line(s).

    Therefore, use ReadLn() instead of Read() when you read user entries.