comp.lang.ada
 help / color / mirror / Atom feed
From: Doraiapp <doraiapp@fdusvrt1.fdu.edu>
Subject: Help with my program
Date: 1997/02/17
Date: 1997-02-17T00:00:00+00:00	[thread overview]
Message-ID: <3308B6FD.507C@fdusvrt1.fdu.edu> (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




             reply	other threads:[~1997-02-17  0:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-02-17  0:00 Doraiapp [this message]
1997-02-18  0:00 ` Help with my program Robert Dewar
1997-02-20  0:00   ` Peter Milliken
1997-02-21  0:00     ` Robert Dewar
replies disabled

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