comp.lang.ada
 help / color / mirror / Atom feed
* A very strange problem indeed...
@ 2002-03-18 14:06 Karl-Johan Karlsson
  2002-03-18 15:22 ` Larry Hazel
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Karl-Johan Karlsson @ 2002-03-18 14:06 UTC (permalink / raw)



Note that the following code details below are to do with the same
program mentioned in the "if statement" thread involving a problem
Steve Doiel helped me with (thanks a lot Steve!).

The problem this time is that the string for the name entry is not
working properly!  If I have Name : String(1..20) it will only
accept 20 characters and nothing less.  If I delete four lines
of the code (found below to do with size and amount) then the
string accepts any amount of characters 20 or less in amount.

   Name : String(1..20);
   Name_Count : Natural;

I have cut the program up into little tiny bits and I've discovered
that the following four lines of code which preceed the Name code
is why my Name string isn't working:

   Put("size you want: ");
   Item_Type_IO.Get(Choice);
   Put("amount you want: ");
   Get(Item_Amount);

(These four lines do exactly what is required of them except that they
 seem to be effecting the Name code...)

These four lines above are the ones which are making my name string accept
only a certain amount of characters (e.g. 20), so if I type less characters
it will not go to the next part of the program.

   Put("Please tell us");
   New_Line;
   Put("your name: ");
   Get_Line(Name, Name_Count);

The Name code above works only when I delete the size and amount code.
So the four lines to do with the size and amount code are the problem,
yet I cannot for the life of me understand why.  Please, any assistance
would be greatly appreciated!

(Note that I need the name code to be just above the amount and item code!)

Using Ada95 under Win98.

Message previously posted:
> 
> 
> 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: A very strange problem indeed...
  2002-03-18 14:06 A very strange problem indeed Karl-Johan Karlsson
@ 2002-03-18 15:22 ` Larry Hazel
  2002-03-18 16:39 ` John McCabe
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Larry Hazel @ 2002-03-18 15:22 UTC (permalink / raw)


Karl-Johan Karlsson wrote:
> 
> Note that the following code details below are to do with the same
> program mentioned in the "if statement" thread involving a problem
> Steve Doiel helped me with (thanks a lot Steve!).
> 
> The problem this time is that the string for the name entry is not
> working properly!  If I have Name : String(1..20) it will only
> accept 20 characters and nothing less.  If I delete four lines
> of the code (found below to do with size and amount) then the
> string accepts any amount of characters 20 or less in amount.
> 
>    Name : String(1..20);
>    Name_Count : Natural;
> 
> I have cut the program up into little tiny bits and I've discovered
> that the following four lines of code which preceed the Name code
> is why my Name string isn't working:
> 
>    Put("size you want: ");
>    Item_Type_IO.Get(Choice);
>    Put("amount you want: ");
>    Get(Item_Amount);
> 
> (These four lines do exactly what is required of them except that they
>  seem to be effecting the Name code...)
> 
> These four lines above are the ones which are making my name string accept
> only a certain amount of characters (e.g. 20), so if I type less characters
> it will not go to the next part of the program.
> 
>    Put("Please tell us");
>    New_Line;
>    Put("your name: ");
>    Get_Line(Name, Name_Count);
> 
> The Name code above works only when I delete the size and amount code.
> So the four lines to do with the size and amount code are the problem,
> yet I cannot for the life of me understand why.  Please, any assistance
> would be greatly appreciated!
> 
> (Note that I need the name code to be just above the amount and item code!)
> 
Not sure I understand the problem, but if the code is in the order above, you
need a Skip_Line call after the Get(Item_Amount), since the Get will not consume
an end_of_line.

Larry



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

* Re: A very strange problem indeed...
  2002-03-18 14:06 A very strange problem indeed Karl-Johan Karlsson
  2002-03-18 15:22 ` Larry Hazel
@ 2002-03-18 16:39 ` John McCabe
  2002-03-18 18:03 ` Jacob Sparre Andersen
  2002-03-19  3:10 ` Karl-Johan Karlsson
  3 siblings, 0 replies; 5+ messages in thread
From: John McCabe @ 2002-03-18 16:39 UTC (permalink / raw)


On 18 Mar 2002 14:06:30 GMT, "Karl-Johan Karlsson" <kjk@tt.com> wrote:

>   Put("size you want: ");
>   Item_Type_IO.Get(Choice);
>   Put("amount you want: ");
>   Get(Item_Amount);

What type is "Item_Amount"? What do you have in your context clauses.
I would suggest, if the code itself isn't very long, get rid of all
the "use" clauses related to IO packages and specify them explicitly. 

>These four lines above are the ones which are making my name string accept
>only a certain amount of characters (e.g. 20), so if I type less characters
>it will not go to the next part of the program.
>
>   Put("Please tell us");
>   New_Line;
>   Put("your name: ");
>   Get_Line(Name, Name_Count);

It's probably worth stripping this right down to a bare minimum
including these lines and posting it on this group. It would make it
easier for everyone if they had the full details, inclufing type
definitions, context etc, and we would all be able to build and run
it.




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

* Re: A very strange problem indeed...
  2002-03-18 14:06 A very strange problem indeed Karl-Johan Karlsson
  2002-03-18 15:22 ` Larry Hazel
  2002-03-18 16:39 ` John McCabe
@ 2002-03-18 18:03 ` Jacob Sparre Andersen
  2002-03-19  3:10 ` Karl-Johan Karlsson
  3 siblings, 0 replies; 5+ messages in thread
From: Jacob Sparre Andersen @ 2002-03-18 18:03 UTC (permalink / raw)


Karl-Johan Karlsson wrote:

>    Put("size you want: ");
>    Item_Type_IO.Get(Choice);
>    Put("amount you want: ");
>    Get(Item_Amount);

Are you certain that you are not missing a:

     Skip_Line;

at this point?  You might want to consider what happens to
the characters (including a possible line break) entered
after the amount.  Have you read the description of the
"Get" procedure properly?

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

There is, as far as I know, no such thing as "Ada98".  You
are most likely using either Ada 2001 (this name is seldom
used in practice, since the 2001 revisions to the language
reference manual were relatively minor) or Ada95.

Jacob
-- 
"There is nothing worse than having only one drunk head."



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

* Re: A very strange problem indeed...
  2002-03-18 14:06 A very strange problem indeed Karl-Johan Karlsson
                   ` (2 preceding siblings ...)
  2002-03-18 18:03 ` Jacob Sparre Andersen
@ 2002-03-19  3:10 ` Karl-Johan Karlsson
  3 siblings, 0 replies; 5+ messages in thread
From: Karl-Johan Karlsson @ 2002-03-19  3:10 UTC (permalink / raw)



Larry Hazel <lhhazel@otelco.net> wrote:
>
>Not sure I understand the problem, but if the code is in the order above, you
>need a Skip_Line call after the Get(Item_Amount), since the Get will not consume
>an end_of_line.

Yes you are correct!  Now my program is complete.  A few times I tried to use a
New_Line which did not work, I can't believe I didn't try a Skip_Line before.

Thank you so very much, Larry.



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

end of thread, other threads:[~2002-03-19  3:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-03-18 14:06 A very strange problem indeed Karl-Johan Karlsson
2002-03-18 15:22 ` Larry Hazel
2002-03-18 16:39 ` John McCabe
2002-03-18 18:03 ` Jacob Sparre Andersen
2002-03-19  3:10 ` Karl-Johan Karlsson

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