Hi all. Have a school thing that I'd like a little assistance with for a friend. Last time I touched programming was probably in 94. Plan to get back into it and use Python still, but see if you can help me out on this.
Needs to accept/store input to a file and be able to print the stored data basically. So like name and payment, then print and total the number of names and the sum of the payment.
On a side note - I'd question why Pascal is still in use in schools. Is there some new version that doesn't run on DOS? I've seen -> http://www.freepascal.org/ <- but again I'm a bit confused as to why schools haven't moved on to C or VB.
Thanks in advance for any assistance provided.
*EDIT*
So far I have what's below. If I can find out how to add the numbers that are searched for in a created file then that would be nice. Unless someone wants to help with the cleanup of the syntax if it needs be done?
ADDING NUMBERS
http://borlandpascal.wikia.com/wiki/...ng_two_numbers
__________________________________________________ ___________________________________________
var a,b,s:integer;
begin
write ('Type a: '); readln (a);
write ('Type b: '); readln (b);
s:=a+b;
writeln ('The sum of a+b is ', s);
readln;
end.
__________________________________________________ ___________________________________________
CREATING A FILE AND WRITING DATA
http://pascal-programming.info/lesson9.php
__________________________________________________ ___________________________________________
Program Lesson9_Program2;
Var FName, Txt : String[10];
UserFile : Text;
Begin
FName := 'Textfile';
Assign(UserFile,'C:\'+FName+'.txt'); {assign a text file}
Rewrite(UserFile); {open the file 'fname' for writing}
Writeln(UserFile,'PASCAL PROGRAMMING');
Writeln(UserFile,'if you did not understand something,');
Writeln(UserFile,'please send me an email to:');
Writeln(UserFile,'victorsaliba@hotmail.com');
Writeln('Write some text to the file:');
Readln(Txt);
Writeln(UserFile,'');
Writeln(UserFile,'The user entered this text:');
Writeln(UserFile,Txt);
Close(UserFile);
End.
__________________________________________________ ___________________________________________
SEARCHING FOR STRING WITHIN FILE
http://www.daniweb.com/software-deve.../threads/52166
__________________________________________________ ___________________________________________
procedure SearchingInFile(Filename, SearchStr :string);
var
SearchPos,
FoundCount :integer;
FileLine :string;
SearchFile :Text;
begin
Assign(SearchFile, Filename);
Reset(SearchFile);
FoundCount := 0;
while not EOF(SearchFile) do
begin
// the <strong class="highlight">search</strong> will be no case sensitive (using UpCase)
FileLine := UpCase(Readln(SearchFile));
SearchPos := Pos(UpCase(SearchStr), FileLine);
if SearchPos > 0 then
begin
// looking for more SearchStr into FileLine
while SearchPos > 0 do
begin
// add 1 to founded word count
Inc(FoundCount);
// Advance SearchPos
SearchPos := SearchPos +Length(SearchStr).
// remove substring before last word founded, including the word
FileLine := Copy(FileLine, SearchPos, Length(FileLine));
// check for a new occurence of searched word on line readed
SearchPos := Pos(UpCase(SearchStr), FileLine);
end;
end;
end;
Close(SearchFile);
end;
__________________________________________________ ___________________________________________