Answer the question
In order to leave comments, you need to log in
Wrote a program (line-number). Where is the mistake?
"Write a program that calculates the sum of three numbers entered as a character string. All numbers are integers. Example: Enter the expression: 12+3+45, Answer: 60"
program A2;
var s,s1,s2,s3: string;
begin
writeln ('Введите три целых числа');
readln (s1);
readln(s2);
readln (s3);
s:=s1+s2+s3;
writeln (s1, '+', s2, '+', s3, '=', s);
readln;
end.
Answer the question
In order to leave comments, you need to log in
You are doing the wrong job. You have one string "12+3+45" as input, not 3 different variables.
Therefore, you must split the string on the "+" characters. And each individual character set, in this case
12, 3, and 45, is converted to a numeric type using StrToInt or Val.
For variables, you need to specify the number type, because. when adding lines, they continue each other:
'1'+'2'+'3'='123'
1+2+3=6
program A2;
var s,s1,s2,s3: integer;
begin
writeln('Введите три целых числа');
readln(s1);
readln(s2);
readln(s3);
s:=s1+s2+s3;
writeln (s1, '+', s2, '+', s3, '=', s);
readln;
end.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question