Here are some ideas for the solution.
An (old-style) ISBN has 10 digits, the last of which is a check digit. So you need to define a variable suitable for reading an ISBN from the screen.
To read and process the characters in the variable from left to right you will use a suitable programming structure - what?
As you read each character you will need to perform a calculation using a number that runs from 10 to 1; you will also need to maintain a running total (also known as a gatherer).
At the end of this process you must perform modulo arithmetic on the total, as shown in the algorithm (search the web for this, it's not hard to find).
When you have the check digit convert it to a string and add it to the end of the original ISBN.
Use the val and str functions to convert between numbers and characters or strings. See here for more detail: String functions explained
Fragments:
var ISBN: ??
n, code : integer;
val (ISBN[i], n, code); //this gives the numeric value of a character as integer n; code is an error code, just include it
str(check_digit, ISBN[?]; //converts a numeric variable to a string; check_digit will be a single character such as 3 or 7 - or 'X' if the result is 10
Code:
program Project1;
var isbn,cd:string[10];
i,total,numeric_value,code,check_digit,weight:integer;
begin
writeln('Enter first 9 digits of ISBN: ');
readln(isbn);
total:=0;
weight:=10;
for i := 1 to 9 do
begin
val(isbn[i],numeric_value,code); //get numeric value of ISBN digit
total:=total+numeric_value*weight; //add subtotal for current digit
dec(weight); //weight goes from 10 downto 2
end;
writeln(total);
check_digit:=11-(total mod 11); //in one line!
if check_digit = 11 then check_digit := 0;
if check_digit=10 then cd:='X'
else str(check_digit,cd);
isbn:=isbn+cd; //add check digit string to isbn string
writeln(check_digit);
writeln(isbn);
end.
Here is an example of a try..except. This traps the error of typing a character instead of a digit.
try
Readln(Choice);
except
on E: Exception do
writeln(' error raised, with message : '+E.Message)
end;