String to Real in Pascal - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

String to Real in Pascal

anddiissanddiiss Posts: 1Member
Hey guys! I'm a newcomer here and I'm having a bit of an emergency with my school project. My teacher asked me to write a program witch lets user input a string line with numbers, names, chars, everything.
For example:
School 5.48 cars 8 b
and so on..
Yeah, that seems easy, but listen what follows next. I have to find all the real values and write them in new line. Okay, I did it, sort of. The only problem is the spacing which seems wrong, I'll show the code.
The reason why am I even asking for help is because I have to change dots of each real value to comma's. How can I do it? And how can I count all of those real values together, they aren't integer, they are string, that means its going to be like that: 5 + 5 = 55 however I want it to be 5+5=10 ..

Here's the code guys. Cheers!

[code]program Project1;

{$APPTYPE CONSOLE}

uses
SysUtils;

var
f:array[1..10]of string = ('0','1','2','3','4','5','6','7','8','9');
a,s,m:string;
l,k,n:integer;
begin
writeln;
writeln('------------------------------------------------------------------------');
writeln('Sis programmas merkis ir izvadit no simbolu rindas realos skaitlus!!');
writeln('Ludzu, ievadiet vairakus simbolus, lai no tiem atlasitu realos skaitlus!');
writeln('------------------------------------------------------------------------');
writeln;

write('Input string line: ');
readln(a);
m:='';
l:=length(a);
for n:=1 to l do
begin
s:=Copy(a,n,1);
if (s = '.') or (s = ' ') then m:=m+s;
for k:=1 to 10 do
begin
s:=Copy(a,n,1);
if (s = (f[k]))then m:=m+s;
end;
end;
writeln;
Write('String lines real values: ');
writeln(m);

readln;


end.[/code]
Sign In or Register to comment.