Hello, guys.
I am using the latest free pascal compiler and I am on windows 11.
I recently got my hands on an old pascal textbook, and I have been trying to learn from it since I have no experience with pascal and my programming skills and problem solving skills aren't great at all (they are really bad), so I wanted to go back to basics to build up a solid foundation this time.
I have encountered a problem trying to replicate one of the examples, the other examples work well but this one doesn't. It compiles but when I try to insert data, it doesn't output anything.
It's supposed to work like this:
INPUT: baa, baa, black sheep.
OUTPUT: 16 Characters, 3 blanks, 2 commas, 1 period
This is the program:
program countchars(input, output);
{$MODE ISO}
const
blank = ' ';
comma = ',';
period = '.';
var
charcount, blankcount, commacount, periodcount: integer;
character : char;
begin
charcount := 0;
commacount := 0;
blankcount := 0;
periodcount := 0;
while not eof do
begin
read(character);
charcount := charcount + 1;
if character = blank
then blankcount := blankcount + 1
else if character = comma
then commacount := commacount + 1
else if character = period
then periodcount := periodcount + 1
end;
writeln (charcount, 'characters');
writeln (blankcount, 'blanks');
writeln (periodcount, 'periods');
writeln (commacount, 'commas');
end.
I am not sure what to do, or what the problem is.
I also encountered another issue, when I tried replacing the "char" type with a "string" type, it returned exit code 201, Apparently this is a range check error and it's trying to store a value where it doesn't fit. I would like to know why, because isn't the string type bigger than the char type, so why does it crash whenever I try storing strings in the string type.
Thank you in advance,
Kenneth.