Alternatively.
unit Wallet;//By Adam N.Andujar
Procedure RemoveFrom;
type
Number = Integer;
Walletrec = Record
Balance,Cost : Number;
END;
var
WalletFile : Text;
INWallet : Walletrec;
Readstr : Integer;
Procedure RemoveFrom; <--- this one is one too much. remove the line
BEGIN
NB. Even after that it will not compile.
It needs
{$mode objfpc} //or {$mode delphi}
or it will stumble upon the assignfile, closefile statements.
More C&C.
Procedure WalletProcedures;
BEGIN
assignfile(WalletFile,'Wallet.dat');
while NOT Fileexists('Wallet.dat') do
//no need for a while loop here.
//a simple if NOT FileExists('Wallet.dat') then would suffice
begin//Make wallet
writeln('Input your current Balance.');
Readln(INWallet.Balance);
rewrite(WalletFile);
writeln(WalletFile,INWallet.Balance);
Closefile(WalletFile);
end;
//you just closed the file, so the next line will give a runtime error
while NOT Eof(WalletFile) Do
//using a while loop would cause an infinitive loop here if the file contains more than 1 line
//because you reset the file before each read and you wull never reach the end of the file
begin//Display Balance
writeln('Current Balance:');
reset(WalletFile);
readln(WalletFile,ReadStr);
writeln(ReadStr);
end;
<snip>
Procedure RemoveFrom;
type
Number = Integer;
Walletrec = Record
Balance,Cost : Number;
END;
var
WalletFile : Text;
INWallet : Walletrec;
Readstr : Integer;
BEGIN
assignfile(WalletFile,'Wallet.dat');
writeln('How Much(Numbers Only)?');
readln(INWallet.Cost);
//Q: What happens if user enters 'Bla' (or anything else that is NOT an Integer) ?
//You'll have to open the file somehow first to test for EOF
while NOT Eof(WalletFile) Do
//Again, why do you need a loop here?
begin//Reads the file
reset(WalletFile);
readln(WalletFile,ReadStr);
rewrite(WalletFile);
Erase(WalletFile);
//Now you try to write to a file you have just ERASED !!
// even so, should that be ReadStr - INWallet.Cost ??
writeln(WalletFile,INWallet.Cost - ReadStr);
//How is this gonna work: the file no longer existst
CloseFile(WalletFile);
writeln('Saved!'); //Saved what? You just ERASED the file (and crashed the program)
end;
END;
Bart