comp.lang.ada
 help / color / mirror / Atom feed
* Help with my program
@ 1997-02-17  0:00 Doraiapp
  1997-02-18  0:00 ` Robert Dewar
  0 siblings, 1 reply; 4+ messages in thread
From: Doraiapp @ 1997-02-17  0:00 UTC (permalink / raw)



I translated a code from java script to ada the code is as follows
with text_io; use text_io;
with stack;
 
procedure calculator is
        package int_io is new integer_io(integer);
        package istack is new stack(integer);
        use int_io, istack;
        ch: character;
        done: exception;
 
        function getint(first_digit: character) return integer is
                n:integer :=0;
                ch: character :=first_digit;
                begin
                loop
                        n :=n * 10 + character'pos(ch) -
character'pos('0');
                        exit when end_of_line;
                        get (ch);
                end loop;
                               
return n;
        end;
 
        procedure process_command(ch: character) is
                a, b: integer;
        begin
                case ch is
                        when '0'..'9' =>
                                push(getint(ch));
                        when 'p' | 'P' =>
pop(a);
                                put(a);
                                new_line;
                        when '-' =>
                                pop(a);
                                put(b);
                                push(b-a);
                        when '+' =>
                                pop(a);
                                put(b);
pop(a);
                                put(b);
                                push(b+a);
                        when 'q' |'Q' =>
                                raise done;
                        when others=>
                                put_line("bad command");
                        end case;
 
                exception
                        when overflow =>
                                put_line("stack overflow");
when underflow =>
                                put_line("stack underflow");
                end process_command;
 
                begin
                        loop
                                put(" > ");
                                get(ch);
                                process_command(ch);
                                skip_line;
 end loop;
                exception
                        when done =>
                                skip_line;
                end calculator;
 But my problem is it says b is never assigned a value and also i need
to change the integer to a user defined one how do i achieve it?

Thanking You
Doraiapp
PS please also reply at doraiapp@fdusvrt1.fdu.edu




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1997-02-21  0:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-02-17  0:00 Help with my program Doraiapp
1997-02-18  0:00 ` Robert Dewar
1997-02-20  0:00   ` Peter Milliken
1997-02-21  0:00     ` Robert Dewar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox