## Pascal

Moderators: None (Apply to moderate this forum)
Number of posts: 14004

This Forum Only

OUTPUT PROBLEMS Posted by darkwave0 on 14 Feb 2010 at 9:52 PM
I'm having trouble with this check writer program. Here are the rules for writing the program. There can be no global variables, and the program must use only procedures to be written in.

Here is the code:

procedure Hundreds(var amount : real; var amtaswords : string; var x, tens: integer);
var
hundreds : integer;
begin

hundreds := trunc(amount) div 100;

case hundreds of
1: amtaswords := amtaswords + 'ONE HUNDRED';
2: amtaswords := amtaswords +'TWO HUNDRED';
3: amtaswords := amtaswords +'THREE HUNDRED';
4: amtaswords := amtaswords +'FOUR HUNDRED';
5: amtaswords := amtaswords +'FIVE HUNDRED';
6: amtaswords := amtaswords +'SIX HUNDRED';
7: amtaswords := amtaswords +'SEVEN HUNDRED';
8: amtaswords := amtaswords +'EIGHT HUNDRED';
9: amtaswords := amtaswords +'NINE HUNDRED';

end;
x := trunc(amount) mod 1000;
Tens := x div 1000;
end;
{********************************************************************}
procedure tens(var amount : real; var amtaswords : string; var x, tens: integer);
var
ones : integer;

begin
tens := trunc(amount) div 10;
case tens of

2: amtaswords := amtaswords +'TWENTY';
3: amtaswords := amtaswords +'THIRTY';
4: amtaswords := amtaswords +'FOURTY';
5: amtaswords := amtaswords +'FIFTY';
6: amtaswords := amtaswords +'SIXTY';
7: amtaswords := amtaswords +'SEVENTY';
8: amtaswords := amtaswords +'EIGHTY';
9: amtaswords := amtaswords +'NINETY';

end;
x := trunc(amount) mod 1000;

ones := x div 100;
end;
{********************************************************************}
procedure ONES(var amount : real; var amtaswords : string; var x, tens: integer);
var
ones : integer;

begin
ones := trunc(amount) div 1;
case ones of
1: amtaswords := amtaswords +'ONE';
2: amtaswords := amtaswords +'TWO';
3: amtaswords := amtaswords +'THREE';
4: amtaswords := amtaswords +'FOUR';
5: amtaswords := amtaswords +'FIVE';
6: amtaswords := amtaswords +'SIX';
7: amtaswords := amtaswords +'SEVEN';
8: amtaswords := amtaswords +'EIGHT';
9: amtaswords := amtaswords +'NINE';

end;
x := trunc(amount) mod 1000;
end;
{********************************************************************}
procedure Output(amount : real; var amtaswords : string);
begin
writeln('***************************************************');
writeln('* #328 *');
writeln('* Bank of Biff *');
writeln('* 2300 E Baseline Rd *');
writeln('* Mesa AZ 85238 ',formatdatetime('mmmm yyyy',Now),' *');
writeln('* *');
writeln('* Amount \$',amount:0:2,' ');
writeln('* *');
writeln('* ', amtaswords,' *'); {<- OUTPUT}
writeln('* *');
writeln('* *');
writeln('* McArnold''s Burgers *');
writeln('* 258 S McQueen Rd *');
writeln('* Gilbert AZ 85233 ________________ *');
writeln('* *');
writeln('* *');
writeln('***************************************************');

end;

var
theamount: real;
words: string;
int1 : integer;
int2 : integer;

begin
data(theamount);
thousands(theamount, words, int1, int2);
hundreds(theamount, words, int1, int2);
tens(theamount, words, int1, int2);
ones(theamount, words, int1, int2);
Output(theamount, words);
end.

----------------------------------------------------------------------
Ok, this is the output if you enter 1235.11:
----------------------------------------------------------------------

ONE THOUSAND

---------------------------------------------------------------------
What I want it to say is:
---------------------------------------------------------------------

ONE THOUSAND TWO HUNDRED THIRTY FIVE DOLLARS AND ELEVEN CENTS

---------------------------------------------------------------------

darkwave0 OUTPUT PROBLEMS on 14 Feb 2010 at 9:52 PM
_Atex_ Re: OUTPUT PROBLEMS on 15 Feb 2010 at 8:52 PM

## Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic