with Ada.Text_IO; use Ada.Text_IO; with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; procedure Chips is Value_Names : constant array(1..6) of String(1..5) := ("white", "red ", "blue ", "green", "black", "gold "); Value_Weights : constant array(1..6) of Positive := ( 1 , 5 , 10 , 20 , 100 , 200 ); function Get_Value_For(Color : in String) return Positive is begin for I in 1..6 loop if Color = Value_Names(I) then return Value_Weights(I); end if; end loop; -- crash end Get_Value_For; function Get_Color_For(Value : in Positive) return String is begin for I in 1..6 loop if Value = Value_Weights(I) then return Value_Names(I); end if; end loop; -- crash end Get_Color_For; -- Lägg till din datatypsdefinition -- och dina underprogram här nedan. type Chips_Type is record Antal: Integer; Color: String(1..5); end record; C1, C2, Sum : Chips_Type; procedure Get(Chips: out Chips_Type) is C: Character; begin Get(Chips.Color); Get(C); Get(Chips.Antal); end Get; function "+"(C1,C2: in Chips_Type) return Chips_Type is A,B,C : Integer; Sum: Chips_Type; Sant_Falskt: Boolean; begin A:=Get_Value_For(C1.Color); B:=Get_Value_For(C2.Color); Sant_Falskt:=True; if B < A then C:=A; A:=B; B:=C; Sant_Falskt:=False; end if; if Sant_Falskt = True then Sum.Color:=Get_Color_For(A); Sum.Antal:=C1.Antal+(C2.Antal*(B/A)); elsif Sant_Falskt = False then Sum.Color:=Get_Color_For(A); Sum.Antal:=C2.Antal+(C1.Antal*(B/A)); end if; return Sum; end "+"; procedure Put(Sum: in Chips_Type) is begin Put(Sum.Color); Put(" "); Put(Sum.Antal,0); end Put; begin Put("Input some chips: "); Get(C1); Skip_Line; Put("Input some more chips: "); Get(C2); Skip_Line; Sum := C1 + C2; New_Line; Put("The sum is "); Put(Sum); Put_Line("."); end Chips;