comp.lang.ada
 help / color / mirror / Atom feed
* if statement
@ 2002-03-17 13:46 Karl-Johan Karlsson
  2002-03-17 16:58 ` Steve Doiel
  2002-03-19 19:23 ` Pheet
  0 siblings, 2 replies; 5+ messages in thread
From: Karl-Johan Karlsson @ 2002-03-17 13:46 UTC (permalink / raw)



Hello to group.

I am currently writing a little program that determines how much a
customer's total cost will be for buying either Item1, Item2, Item3
multiplied by the amount purchased (customer cannot purcase a combination
of items, just one at any amount).  If the customer buys more than one
of Item3 the postage price is FREE.  This is where I have confronted trouble
as when Item3 at two or more units purchased is inputted into the
program, the output displays two costs (cost with delivery, cost
without delivery) where I desire only the cost without delivery
to be displayed.  I know this is because the code below needs to
be altered, but I am not sure how to go about doing it so I
require help.

(There are if, elsif entries for Item1, Item2 prior to this code)

      ...
      elsif Choice = Item3 then
      Sum := Item_Amount * Item_Type + Postage_Charge;
      Put("$");
      Put(Sum, 1, 2, 0);

      if Item_Amount > 1 then
      Sum := Item_Amount * Item_Type
      Put("$");
      Put(Sum, 1, 2, 0);
      ...

Also, I am using Ada98, not Ada83 under Win98.



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

* Re: if statement
  2002-03-17 13:46 if statement Karl-Johan Karlsson
@ 2002-03-17 16:58 ` Steve Doiel
  2002-03-19 19:23 ` Pheet
  1 sibling, 0 replies; 5+ messages in thread
From: Steve Doiel @ 2002-03-17 16:58 UTC (permalink / raw)



"Karl-Johan Karlsson" <kjk@tt.com> wrote in message
news:3c949e41$0$7409@motown.iinet.net.au...
>
> Hello to group.
>
> I am currently writing a little program that determines how much a
> customer's total cost will be for buying either Item1, Item2, Item3
> multiplied by the amount purchased (customer cannot purcase a combination
> of items, just one at any amount).  If the customer buys more than one
> of Item3 the postage price is FREE.  This is where I have confronted
trouble
> as when Item3 at two or more units purchased is inputted into the
> program, the output displays two costs (cost with delivery, cost
> without delivery) where I desire only the cost without delivery
> to be displayed.  I know this is because the code below needs to
> be altered, but I am not sure how to go about doing it so I
> require help.
>
> (There are if, elsif entries for Item1, Item2 prior to this code)
>
>       ...
>       elsif Choice = Item3 then
>       Sum := Item_Amount * Item_Type + Postage_Charge;
>       Put("$");
>       Put(Sum, 1, 2, 0);
>
>       if Item_Amount > 1 then
>       Sum := Item_Amount * Item_Type
>       Put("$");
>       Put(Sum, 1, 2, 0);
>       ...
>

Try this (you were almost there)

      elsif Choice = Item3 then
        Sum := Item_Amount * Item_Type;
        if Item_Amount < 2 then
          Sum := Sum + Postage_Charge;
        end if;
        Put("$");
        Put(Sum, 1, 2, 0);
      end if

> Also, I am using Ada98, not Ada83 under Win98.

Presumably you mean Ada95 :-)

SteveD





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

* Re: if statement
  2002-03-17 13:46 if statement Karl-Johan Karlsson
  2002-03-17 16:58 ` Steve Doiel
@ 2002-03-19 19:23 ` Pheet
  1 sibling, 0 replies; 5+ messages in thread
From: Pheet @ 2002-03-19 19:23 UTC (permalink / raw)




Karl-Johan Karlsson wrote:
> 
> Hello to group.
> 
> I am currently writing a little program that determines how much a
> customer's total cost will be for buying either Item1, Item2, Item3
> multiplied by the amount purchased (customer cannot purcase a combination
> of items, just one at any amount).  If the customer buys more than one
> of Item3 the postage price is FREE.  This is where I have confronted trouble
> as when Item3 at two or more units purchased is inputted into the
> program, the output displays two costs (cost with delivery, cost
> without delivery) where I desire only the cost without delivery
> to be displayed.  I know this is because the code below needs to
> be altered, but I am not sure how to go about doing it so I
> require help.
> 
> (There are if, elsif entries for Item1, Item2 prior to this code)
> 
>       ...
>       elsif Choice = Item3 then
>       Sum := Item_Amount * Item_Type + Postage_Charge;
>       Put("$");
>       Put(Sum, 1, 2, 0);
> 
>       if Item_Amount > 1 then
>       Sum := Item_Amount * Item_Type
>       Put("$");
>       Put(Sum, 1, 2, 0);
>       ...
> 
Hi, I think you might try this:

	...
	elsif Choice = Item3 then
		if Item_Amount > 1 then
			Sum:=Item_Amount * Item_Type;
		else
			Sum:=Item_Amount+Postage_Charge;
		end if;
		Put("$");
		Put(Sum,1,2,0);
	end if;
	...

HTH,

Pheet



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

* Re: if statement
@ 2002-03-20  6:05 Christoph Grein
  2002-03-21  6:25 ` Simon Wright
  0 siblings, 1 reply; 5+ messages in thread
From: Christoph Grein @ 2002-03-20  6:05 UTC (permalink / raw)


>       Put(Sum, 1, 2, 0);

Note that in Ada you have named parameter associations. The above is hardly 
readable, who remembers which is which. Use instead

   Put (Sum, Fore => ..., Aft => ..., Exp => ...);

But please do not exaggerate as some do by always writing

   P (X => X, Y => Y)

for all subprogram calls where the named association does not add any 
information. However

  arctan (X => X, Y => Y)

is a completely different beast. The definition has parameter Y first, X second 
(for good mathematical reasons), so if you simply write

  arctan (X, Y)

it's unclear whether you really meant

  arctan (X => X, Y => Y)

or

  arctan (X => Y, Y => X)

So always try to give as much information as possible by providing named 
associations. If actual parameter names already provide enough and types are 
different, there is no need to use named association.



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

* Re: if statement
  2002-03-20  6:05 Christoph Grein
@ 2002-03-21  6:25 ` Simon Wright
  0 siblings, 0 replies; 5+ messages in thread
From: Simon Wright @ 2002-03-21  6:25 UTC (permalink / raw)


Christoph Grein <christoph.grein@eurocopter.com> writes:

>   arctan (X => X, Y => Y)
> 
> is a completely different beast. The definition has parameter Y
> first, X second (for good mathematical reasons),

And if you actually want

  arctan (X => Y, Y => X)

because you're measuring angles clockwise from North ... actually I
guess a renaming would be good;

  function Compass_Bearing (Eastings, Northings : Float'base) return Float'Base)
  renames Arctan (X => Northings, Y => Eastings);

(uncompiled)

-- 
Simon Wright                       Work Email: simon.j.wright@amsjv.com
Alenia Marconi Systems                        Voice: +44(0)23-9270-1778
Integrated Systems Division                     FAX: +44(0)23-9270-1800



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

end of thread, other threads:[~2002-03-21  6:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-03-17 13:46 if statement Karl-Johan Karlsson
2002-03-17 16:58 ` Steve Doiel
2002-03-19 19:23 ` Pheet
  -- strict thread matches above, loose matches on Subject: below --
2002-03-20  6:05 Christoph Grein
2002-03-21  6:25 ` Simon Wright

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