comp.lang.ada
 help / color / mirror / Atom feed
* explain error to me
@ 2001-07-05 22:18 Beau
  2001-07-05 22:41 ` Don't read any more, I am an idiot. Fixed it myself Beau
  2001-07-05 22:48 ` explain error to me chris.danx
  0 siblings, 2 replies; 5+ messages in thread
From: Beau @ 2001-07-05 22:18 UTC (permalink / raw)


I am getting an error can someone help:
the spec file as follows:
----------------------------------------------------------------
--This is the Spec file for the package Print_Table.
--created by Beau Elliott
---------------------------------------------------------------------

PACKAGE Print_Table IS

--------------------------------------------------------------------------
--declarations needed in the package

SUBTYPE IDnumbers IS Natural RANGE 0..9999; --subtype for ID numbers

TYPE HouseHolds IS RECORD  --record for each house containing its ID
 ID : IDnumbers;         --number, Annual Income, and the number of
 Income : Natural;       --People living there
 Members : Positive;
END RECORD;

SUBTYPE ArrayCounter IS Natural RANGE 1..25; --counter for the number of
       --houses we are using
ArraySize : CONSTANT Positive := 25;

TYPE HouseArrays IS ARRAY (ArraySize) OF HouseHolds;

ListofHouses : HouseArrays;

Poverty : Natural;  --variable to tell if the house lives under or above
                    --poverty

Pause : Character;  --pause between reading of tables

------------------------------------------------------------------------
--procedures needed are:

Procedure PrintList(ListofHouses : HouseHolds);
--pre: ListofHouses array is passed already defined
--post: The ListofHouses is printed on the screen

Procedure AboveAverageIncome(ListofHouses : HouseHolds);
--pre: ListofHouses array is passed already defined
--post: The list of Houses that is above the poverty line is printed
--------along with the ID and Income of the house

Procedure BelowAverageIncome(ListofHouses : HouseHolds);
--pre: ListofHouses array is passed already defined
--post: The list of houses that is below poverty rate is printed
--------with the House's ID

END Print_Table;

----------------------------------------------------------------------------
------------------------------------------------------------------
the body of the package is as follows:
-----------------------------------------------------
WITH Ada.Text_IO;
USE Ada.Text_IO;
WITH Ada.Integer_Text_IO;
USE Ada.Integer_Text_IO;


PACKAGE BODY Print_Table IS

 PROCEDURE PrintList(ListofHouses : HouseArrays) IS

 BEGIN
  Put(Item => "Household Income Table. This will tell 25 ");
  New_Line;
  Put(Item => "Houses ID number, Annual Income, and how many ");
  Put(Item => "people live there.");
  New_Line(Spacing => 3);
  Put(Item => "Identification Number    Annual Income");
  Put(Item => "      Household Numbers");
  New_Line;
  Put(Item => "__________________________________________________");
  New_Line;

  FOR Counter IN ArrayCounter LOOP
   Put(Item => ListofHouses(Counter).ID, width => 6);
   Put(Item => ListofHouses(Counter).Income, Width => 6);
   Put(Item => ListofHouses(Counter).Members, Width => 6);
   New_Line;
  END LOOP;

 END PrintList;


 PROCEDURE AboveAverageIncome(ListofHouses : HouseHolds) IS

  BEGIN
   Put(Item => "This Table will represent each house that is ");
   New_Line;
   Put(Item => "above the poverty line.");
   New_Line(Spacing => 3);
   Put(Item => "Identification Number      Annual Income");
   New_Line;
   Put(Item => "_______________________________________________");
   New_Line;

   FOR Counter IN ArrayCounter LOOP
    Poverty := 0;
    Poverty := 6500 + (750 * (ListofHouses(Counter).Member - 2));

    IF ListofHouses(Counter).Income >= Poverty THEN
     Put(Item => ListofHouses(Counter).ID, Width => 6);
     Put(Item => ListofHouses(Counter).Income, Width => 6);

    END IF;
    New_Line;
   END LOOP;
  END AboveAverageIncome;

 PROCEDURE BelowAverageIncome(ListofHouses : HouseHolds) IS

  BEGIN
   Put(Item => "This table will represent each house that is below");
   New_Line;
   Put(Item => "the poverty line.");
   New_Line(Spacing => 3);
   Put(Item => "Identification Number");
   Put(ITem => "________________________");
   FOR Counter IN ArrayCounter LOOP
    Poverty := 0;
    Poverty := 6500 + (750 * (ListofHouses(Counter).Member - 2));
    IF ListofHouses(Counter).Income < Poverty THEN
     Put(Item => ListofHouses(Counter).ID, Width => 6);
    END IF;
    New_Line;
   END LOOP;

  END BelowAverageIncome;

END Print_Table;
--
~Beau~
beau@hiwaay.net






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

* Re: Don't read any more, I am an idiot. Fixed it myself
  2001-07-05 22:18 explain error to me Beau
@ 2001-07-05 22:41 ` Beau
  2001-07-05 22:53   ` chris.danx
  2001-07-05 22:48 ` explain error to me chris.danx
  1 sibling, 1 reply; 5+ messages in thread
From: Beau @ 2001-07-05 22:41 UTC (permalink / raw)


subject explains it all
"Beau" <beau@hiwaay.net> wrote in message
news:tk9pumjsd3j8b3@corp.supernews.com...
> I am getting an error can someone help:
> the spec file as follows:
> ----------------------------------------------------------------
> --This is the Spec file for the package Print_Table.
> --created by Beau Elliott
> ---------------------------------------------------------------------
>
> PACKAGE Print_Table IS
>
> --------------------------------------------------------------------------
> --declarations needed in the package
>
> SUBTYPE IDnumbers IS Natural RANGE 0..9999; --subtype for ID numbers
>
> TYPE HouseHolds IS RECORD  --record for each house containing its ID
>  ID : IDnumbers;         --number, Annual Income, and the number of
>  Income : Natural;       --People living there
>  Members : Positive;
> END RECORD;
>
> SUBTYPE ArrayCounter IS Natural RANGE 1..25; --counter for the number of
>        --houses we are using
> ArraySize : CONSTANT Positive := 25;
>
> TYPE HouseArrays IS ARRAY (ArraySize) OF HouseHolds;
>
> ListofHouses : HouseArrays;
>
> Poverty : Natural;  --variable to tell if the house lives under or above
>                     --poverty
>
> Pause : Character;  --pause between reading of tables
>
> ------------------------------------------------------------------------
> --procedures needed are:
>
> Procedure PrintList(ListofHouses : HouseHolds);
> --pre: ListofHouses array is passed already defined
> --post: The ListofHouses is printed on the screen
>
> Procedure AboveAverageIncome(ListofHouses : HouseHolds);
> --pre: ListofHouses array is passed already defined
> --post: The list of Houses that is above the poverty line is printed
> --------along with the ID and Income of the house
>
> Procedure BelowAverageIncome(ListofHouses : HouseHolds);
> --pre: ListofHouses array is passed already defined
> --post: The list of houses that is below poverty rate is printed
> --------with the House's ID
>
> END Print_Table;
>
> --------------------------------------------------------------------------
--
> ------------------------------------------------------------------
> the body of the package is as follows:
> -----------------------------------------------------
> WITH Ada.Text_IO;
> USE Ada.Text_IO;
> WITH Ada.Integer_Text_IO;
> USE Ada.Integer_Text_IO;
>
>
> PACKAGE BODY Print_Table IS
>
>  PROCEDURE PrintList(ListofHouses : HouseArrays) IS
>
>  BEGIN
>   Put(Item => "Household Income Table. This will tell 25 ");
>   New_Line;
>   Put(Item => "Houses ID number, Annual Income, and how many ");
>   Put(Item => "people live there.");
>   New_Line(Spacing => 3);
>   Put(Item => "Identification Number    Annual Income");
>   Put(Item => "      Household Numbers");
>   New_Line;
>   Put(Item => "__________________________________________________");
>   New_Line;
>
>   FOR Counter IN ArrayCounter LOOP
>    Put(Item => ListofHouses(Counter).ID, width => 6);
>    Put(Item => ListofHouses(Counter).Income, Width => 6);
>    Put(Item => ListofHouses(Counter).Members, Width => 6);
>    New_Line;
>   END LOOP;
>
>  END PrintList;
>
>
>  PROCEDURE AboveAverageIncome(ListofHouses : HouseHolds) IS
>
>   BEGIN
>    Put(Item => "This Table will represent each house that is ");
>    New_Line;
>    Put(Item => "above the poverty line.");
>    New_Line(Spacing => 3);
>    Put(Item => "Identification Number      Annual Income");
>    New_Line;
>    Put(Item => "_______________________________________________");
>    New_Line;
>
>    FOR Counter IN ArrayCounter LOOP
>     Poverty := 0;
>     Poverty := 6500 + (750 * (ListofHouses(Counter).Member - 2));
>
>     IF ListofHouses(Counter).Income >= Poverty THEN
>      Put(Item => ListofHouses(Counter).ID, Width => 6);
>      Put(Item => ListofHouses(Counter).Income, Width => 6);
>
>     END IF;
>     New_Line;
>    END LOOP;
>   END AboveAverageIncome;
>
>  PROCEDURE BelowAverageIncome(ListofHouses : HouseHolds) IS
>
>   BEGIN
>    Put(Item => "This table will represent each house that is below");
>    New_Line;
>    Put(Item => "the poverty line.");
>    New_Line(Spacing => 3);
>    Put(Item => "Identification Number");
>    Put(ITem => "________________________");
>    FOR Counter IN ArrayCounter LOOP
>     Poverty := 0;
>     Poverty := 6500 + (750 * (ListofHouses(Counter).Member - 2));
>     IF ListofHouses(Counter).Income < Poverty THEN
>      Put(Item => ListofHouses(Counter).ID, Width => 6);
>     END IF;
>     New_Line;
>    END LOOP;
>
>   END BelowAverageIncome;
>
> END Print_Table;
> --
> ~Beau~
> beau@hiwaay.net
>
>
>





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

* Re: explain error to me
  2001-07-05 22:18 explain error to me Beau
  2001-07-05 22:41 ` Don't read any more, I am an idiot. Fixed it myself Beau
@ 2001-07-05 22:48 ` chris.danx
  2001-07-06  2:01   ` Jeffrey Carter
  1 sibling, 1 reply; 5+ messages in thread
From: chris.danx @ 2001-07-05 22:48 UTC (permalink / raw)



"Beau" <beau@hiwaay.net> wrote in message
news:tk9pumjsd3j8b3@corp.supernews.com...
> I am getting an error can someone help:
> the spec file as follows:

Beau,

I'm not bashing you, but could you please provide the error next time.  Like I
say it's not that i'm bashing you, it helps ppl help you, sometimes without the
need to compile your source.


I got this error
    "print_table.ads:23:28: invalid subtype mark in discrete range"

which refered to this line

TYPE HouseArrays IS ARRAY (ArraySize) OF HouseHolds;

Arraysize is defined like this

ArraySize : CONSTANT Positive := 25;


The error is due to the fact that ArraySize is not a range, but a constant.  25
is not the same as 1..25, so Ada rejects this.

You could do one of the following

1) declare HouseArrays like this

TYPE HouseArrays IS ARRAY (1..ArraySize) OF HouseHolds;

2) declare a type like this

-- a type representing the range of the number
-- of houses
SUBTYPE NumHouses is Natural range 1..25;

then declare houseArrays like this

TYPE HouseArrays IS ARRAY (NumHouses'first..NumHouses'last) OF HouseHolds;

3) Reuse ArrayCounter type as in 2.

TYPE HouseArrays IS ARRAY (ArrayCounter'first..ArrayCounter'last) OF HouseHolds;



I'm assuming that you've learned about attributes for 2 and 3.  In the computing
science course at glasgow uni, they taught this near the beginning when they
taught strings and string declarations.  This is why i'm assuming attributes, if
you don't know what they are stick with solution 1 and/or just ask and some one
here.  ( I know you like extra cred :-) )

Hope this helps,
Chris Campbell




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

* Re: Don't read any more, I am an idiot. Fixed it myself
  2001-07-05 22:41 ` Don't read any more, I am an idiot. Fixed it myself Beau
@ 2001-07-05 22:53   ` chris.danx
  0 siblings, 0 replies; 5+ messages in thread
From: chris.danx @ 2001-07-05 22:53 UTC (permalink / raw)


It's an easy thing to do, done it myself (i used to be a pascal programmer and
this is legal and indeed expected in pascal, so it is sometimes confusing).
It's good that you fixed it yourself; you didn't give up and wait for an answer,
like some folk.


Regards,
Chris




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

* Re: explain error to me
  2001-07-05 22:48 ` explain error to me chris.danx
@ 2001-07-06  2:01   ` Jeffrey Carter
  0 siblings, 0 replies; 5+ messages in thread
From: Jeffrey Carter @ 2001-07-06  2:01 UTC (permalink / raw)


"chris.danx" wrote:
> 
> 2) declare a type like this
> 
> -- a type representing the range of the number
> -- of houses
> SUBTYPE NumHouses is Natural range 1..25;
> 
> then declare houseArrays like this
> 
> TYPE HouseArrays IS ARRAY (NumHouses'first..NumHouses'last) OF HouseHolds;

This is better written as

type House_Arrays is array (Numhouses) of Households;

> 
> 3) Reuse ArrayCounter type as in 2.
> 
> TYPE HouseArrays IS ARRAY (ArrayCounter'first..ArrayCounter'last) OF HouseHolds;

Again, this would be better with just "(Arraycounter)" for the range.

-- 
Jeff Carter
"You tiny-brained wipers of other people's bottoms!"
Monty Python & the Holy Grail



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

end of thread, other threads:[~2001-07-06  2:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-07-05 22:18 explain error to me Beau
2001-07-05 22:41 ` Don't read any more, I am an idiot. Fixed it myself Beau
2001-07-05 22:53   ` chris.danx
2001-07-05 22:48 ` explain error to me chris.danx
2001-07-06  2:01   ` Jeffrey Carter

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