All pastes #970368 Raw Edit

ada

public text v1 · immutable
·published 2008-04-04 00:29 UTC
rendered paste body
with Ada.Text_IO;
use Ada.Text_IO;

procedure Country is 

    type Cars is
        (Ford,Chevrolet,Pontial,Chrysler,Dodge,
        Rover,Rolls_Royce,
        Peugeot,Renault,Citroen,
        BMW,Volkswagen,Opel,Audi,
        Honda,Toyota,Mitsubishi,
        Daewoo,Kia,Hyundai
        );

    type Countries is (UK,US,France,Germany,Korea,Japan);

    function Car_to_Country(C: Cars) return Countries is
    begin

        case C is
            when Ford..Dodge => return US;
            when Rover|Rolls_Royce => return UK;
            when Peugeot..Citroen => return France;
            when BMW..Audi => return Germany;
            when Daewoo..Hyundai => return Korea;
            when Honda..Mitsubishi => return Japan;
        end case;
    end Car_to_Country;

    S: String(1..80);
    Last: Integer;
    Car: Cars;

    begin
        loop
            Put("Enter the maker of the car: ");
            Get_Line(S,Last);
            exit when Last=0;
            Car:=Cars'Value(S(1..Last));
            Put_Line(Cars'Image(Car) & " is made in " & Countries'Image(Car_to_Country(Car)));
        end loop;
    exception
        when Constraint_Error =>
            Put_Line(S(1..Last) & " is not in cars list");
end Country;