{$mode objfpc}{$H-}{$R+}{$T+}{$Q+}{$V+}{$D+}{$X-}{$warnings on}
program divisas;

function obtener_USDEUR():real;
    // En un programa real, consultaríamos el precio actual
    // en algún servicio online
const
    USDEUR : real = 0.986;  // Constante propia de esta función
begin
    result := USDEUR;
end;

function obtener_USDGBP():real;
const
    USDGBP : real = 0.771;
begin
    result := USDGBP;
end;

function a_dolar(importe:real; divisa: string):real;
begin
    if divisa ='EUR' then
        result := importe / obtener_USDEUR()
    else if divisa = 'GBP' then
        result := importe / obtener_USDGBP()
    else if divisa = 'USD' then
        result := importe
    else begin
        writeln('ERROR. ¡Esto no debería suceder!');
        halt;  // Detiene la ejecución del programa
    end
end;

function precon_a_dolar(divisa:string): boolean;
begin
    result := (divisa = 'EUR') or (divisa = 'GBP') or (divisa = 'USD');
end;

const
    Importe1 : real = 200;  // Importe
    Divisa1 : string = 'EUR';  // Divisa

    Importe2 : real = 4.30;
    Divisa2 : string = 'GBP';
  
    Importe3: real = 704.21;
    Divisa3: string = 'USD';

begin  // Cuerpo principal
    // Aún no podemos hacer esto bien porque aún no hemos
    // visto procedimientos
    if precon_a_dolar(Divisa1) then begin
        write( Importe1:0:2 , ' ' , Divisa1);
        writeln( ' son ', a_dolar(Importe1, Divisa1):0:2, ' USD');
    end
    else begin
        write('Divisa no reconocida', Divisa1);
    end;

    if precon_a_dolar(Divisa2) then begin
        write( Importe2:0:2 , ' ' ,  Divisa2);
        writeln( ' son ', a_dolar(Importe2, Divisa2):0:2, ' USD');
    end
    else begin
        write('Divisa no reconocida', Divisa2);
    end;

    if precon_a_dolar(Divisa3) then begin
        write( Importe3:0:2 , ' ' , Divisa3);
        writeln( ' son ', a_dolar(Importe3, Divisa3):0:2, ' USD');
    end
    else begin
        write('Divisa no reconocida', Divisa3);
    end;

end.
