Reputation: 691
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;
Upvotes: 0
Views: 428
Reputation: 6611
last_c0 : Character := element (c0, length (c0));
is likely to solve your problem.
Upvotes: 2