0

I am experimenting with my first Ada program (Ada 2012) and running into some difficulties. I am getting input from the user and storing this into a number of unbounded strings. Then I am passing these unbounded strings into a procedure where I extract the last element of each of the unbounded strings and add that to the character array. I read that arrays need to be instantiated as types, but when I do so, I run into errors, so I instantiated without the type reference.

The problem comes in with

 last: Character := c0.Last; 

I am getting an "invalid prefix in selected component "c0"" error.

Below is the code so far:

with Ada.Text_IO, Ada.Integer_Text_IO, Ada.Strings.Unbounded.Text_IO; use Ada.Text_IO, Ada.Integer_Text_IO, Ada.Strings.Unbounded, Ada.Strings.Unbounded.Text_IO; procedure game is card0: Unbounded_String; card1: Unbounded_String; card2: Unbounded_String; card3: Unbounded_String; card4: Unbounded_String; cardNumArray: array (1..5) of Integer; suiteArray: array (1..5) of Character; procedure setUpData(c0, c1, c2, c3, c4: in Unbounded_String) is last_c0: Character := c0.Last; begin suiteArray := (last_c0, 'S', 'S', 'H', 'S'); end setUpData; begin Put_Line ("Enter your card details:\n"); Put_Line ("Enter card 1, e.g. ""AH:"" "); Get_Line(card0); Put_Line ("Enter card 2, e.g. ""KH:"" "); Get_Line(card1); Put_Line ("Enter card 3, e.g. ""QH:"" "); Get_Line(card2); Put_Line ("Enter card 4, e.g. ""10H:"" "); Get_Line(card3); Put_Line ("Enter card 5, e.g. ""JH:"" "); Get_Line(card4); setUpData(card0, card1, card2, card3, card4); end game; 
4
  • Why do you expect to be able to write c0.Last, when c0 is an Unbounded_String? Commented Aug 8, 2015 at 9:45
  • Have you browsed section A.4.5 in the Language Reference Manual? It may help you. Commented Aug 8, 2015 at 10:41
  • As an occasional card player I feel obliged to tell you that cards have "suits", not "suites". Commented Aug 9, 2015 at 0:04
  • Duly noted. Thank you. Commented Aug 9, 2015 at 8:56

1 Answer 1

2
last_c0 : Character := element (c0, length (c0)); 

is likely to solve your problem.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.