Recent

Author Topic: an error in pascal exercise  (Read 4079 times)

hilary

  • New member
  • *
  • Posts: 7
an error in pascal exercise
« on: May 15, 2015, 03:35:14 am »
My code in text editor:

program InvestmentCal;
uses TerminalUserInput, Math;

var
function CompoundInterest(principle, years: Integer; interest: Double): Double;
   compound_interest: Double;
begin
   compound_interest := principle * power(1 + interest, years) - principle;
   result := compound_interest;
end;

procedure Main();
var
   enterPrinciple, enterInterest, compound_interest: Double;
begin
   enterPrinciple := ReadDouble('Enter principle: ');
   enterInterest := ReadDouble('Enter interest: ');

Result from terminal:

Free Pascal Compiler version 2.6.4 [2014/02/26] for i386
Copyright (c) 1993-2014 by Florian Klaempfl and others
Target OS: Darwin for i386
Compiling InvestmentCal.pas
InvestmentCal.pas(8,51) Error: Identifier not found "interest"
InvestmentCal.pas(18,53) Error: Incompatible type for arg no. 1: Got "Double", expected "LongInt"
InvestmentCal.pas(29,4) Fatal: There were 2 errors compiling module, stopping
Fatal: Compilation aborted
Error: /usr/local/bin/ppc386 returned an error exitcode (normal if you did not specify a source file to be compiled)
   compound_interest := CompoundInterest(enterPrinciple, 5, enterInterest);
   writeln('Compound interest is ', compound_interest);


end;

InvestmentCal.pas(8,51) Error: Identifier not found "interest"
refers to this line
compound_interest := principle * power(1 + interest, years) - principle;

what have i done wrong?

hilary

  • New member
  • *
  • Posts: 7
Re: an error in pascal exercise
« Reply #1 on: May 15, 2015, 03:50:19 am »
hey guys, i solved the 1st error already, pls focus on the 2nd error.

hilary

  • New member
  • *
  • Posts: 7
Re: an error in pascal exercise
« Reply #2 on: May 15, 2015, 03:54:49 am »
hey guys, i solved the 2 errors already, here is my current final version.

program InvestmentCal;
uses TerminalUserInput, Math;

function CompoundInterest(principle, years: Integer; interest: Double): Double;
var
   compound_interest: Double;
begin
   compound_interest := principle * power(1 + interest, years) - principle;
   result := compound_interest;
end;

procedure Main();
var
   enterPrinciple: Integer;
   enterInterest, compound_interest: Double;
begin
   enterPrinciple := ReadInteger('Enter principle: ');
   enterInterest := ReadDouble('Enter interest: ');
   compound_interest := CompoundInterest(enterPrinciple, 5, enterInterest);
   writeln('Compound interest is ', compound_interest);


end;

BitBangerUSA

  • Full Member
  • ***
  • Posts: 183
Re: an error in pascal exercise
« Reply #3 on: May 15, 2015, 04:32:26 am »
good.

1st version missing something - no proper end to program (and maybe no call/use to the function you set-up) and no variables after first 'var' line.

understanding program structure is important, no?
Lazarus Ver 2.2.6 FPC Ver 3.2.2
Windows 10 Pro 64-bit

 

TinyPortal © 2005-2018