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

* Re: Help with my program
  1997-02-17  0:00 Help with my program Doraiapp
@ 1997-02-18  0:00 ` Robert Dewar
  1997-02-20  0:00   ` Peter Milliken
  0 siblings, 1 reply; 4+ messages in thread
From: Robert Dewar @ 1997-02-18  0:00 UTC (permalink / raw)



Doriapp says

<< 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?>>

The reason it says that b is never assigned a value is that b is never
assigned a value, as is clear from your code!

I do not understand your confusion





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

* Re: Help with my program
  1997-02-18  0:00 ` Robert Dewar
@ 1997-02-20  0:00   ` Peter Milliken
  1997-02-21  0:00     ` Robert Dewar
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Milliken @ 1997-02-20  0:00 UTC (permalink / raw)



Robert Dewar wrote:
> 
> Doriapp says
> 
> << 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?>>
> 
> The reason it says that b is never assigned a value is that b is never
> assigned a value, as is clear from your code!
> 
> I do not understand your confusion

Gee... that was REAL helpful, or perhaps you didn't read the message
title? Is this what Mike was talking about several weeks ago when he
mentioned how helpful the DJGPP community was and that perhaps we ought
to foster the same kind of comraderie (very much paraphrased here, sorry
Mike, I believe this was the gist of what you were talking about). I
have never seen anyone in the djgpp list respond like this!

Dear Doriapp, I assume from a quick look at you code you are trying to
implement a RPN Calculator. In which case, something like the '+' case
should be:

                        when '+' =>
                                -- case assumes that the user has
entered two numbers :-)
                                pop(a);
                                pop(b);
                                push(b+a);

This will assign the value to 'b' and achieve what I (believe) you want
from the exercise.

Good Luck
Peter


-- 
Peter Milliken                                     _--_|\
peterm@zip.com.au (personal)                      /      \
peterm@cae.com.au (business)                      \_.--._/
                                                        v




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

* Re: Help with my program
  1997-02-20  0:00   ` Peter Milliken
@ 1997-02-21  0:00     ` Robert Dewar
  0 siblings, 0 replies; 4+ messages in thread
From: Robert Dewar @ 1997-02-21  0:00 UTC (permalink / raw)



Peter said

<<Gee... that was REAL helpful, or perhaps you didn't read the message
title? Is this what Mike was talking about several weeks ago when he
mentioned how helpful the DJGPP community was and that perhaps we ought
to foster the same kind of comraderie (very much paraphrased here, sorry
Mike, I believe this was the gist of what you were talking about). I
have never seen anyone in the djgpp list respond like this!>>

I assumed (perhaps wrongly, but I doubt it) that this was a homework 
excercise. Peter may *think* that he is helping by doing other peoples
homework assignments, but in fact it is harmful. Doing you own work in
figuring out homework assignments is one of the most important ways of
learning, and you short circuit this if you spoon feed answersw.

In this case, the student (again I am assuming this was a student doing
a home work excercise), had declared a variable b, which was not otherwise
referenced in the program, and could not understand the diagnostic that
commented that b was never assigned a value.

Peter's help consisted of writing the code for the student that used b,
but I don't think that's helpful. Obvsiouly there is a very fundamental
lack of comprehension here, and it is not easy to even address this
level of lack of comprehension. If you do not understand that variaboles
in your program are declared because they are to be used for some purpose,
then you are missing some very fundamental grasp of what programs are
all about.

Supplying incomprehensible code is NOT the way to help some one with
this level of confusion. What you need to do is to ask the person WHY
they do not understand a message like this, as I did. From that answer
you will be able to get to the bottom of the misunderstanding.

Remember that the problem here is not to write a calculator program, it is
to understand HOW to write a calculator program. it is very easy to help
with the first problem (as Peter did), it is MUCH harder to help with the
second.

A friendly atmosphere in which students can easily get others to write
ttheir assignments for them may look nice, and short-sighted students
will no doubt find it nice, but it is NOT being helpful to them!

RObert





^ 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