Hola urutia.
Veo no llevas mucho tiempo en el foro, te aconsejo crear un
nuevo hilo con el tus inquietudes, si no es muy probable que queden sin respuesta
.
Bueno a ver...
Primero funciones: Potencia y Factorial. (usando ciclos)
Código:
function Potencia(x: Single; y:Integer): Double;
begin
Result:= 1;
while y > 0 do
begin
Result := Result * x;
Dec(y);
end;
end;
function Factorial(Num: Integer): LongInt;
begin
Result:= 1;
while Num > 1 do
begin
Result:= Result * Num;
Dec(Num);
end;
end;
Para verificar si es número:
Código:
function EsNumero(Valor: string): Boolean;
var
n,cd: Integer;
begin
Val(Valor, n, cd);
Result:= cd = 0;
end;
Por último verificar a la salida de los TEdit's:
Código:
procedure TForm1.EditXExit(Sender: TObject);
begin
if not EsNumero(EditX.Text) then
begin
ShowMessage('Número inválido');
EditX.SetFocus;
end;
end;
procedure TForm1.EditYExit(Sender: TObject);
begin
if not EsNumero(EditY.Text) then
begin
ShowMessage('Número inválido');
EditY.SetFocus;
Exit;
end;
if not Odd(StrToInt(EditY.Text) then
begin
ShowMessage('Ingrese un número impar');
EditY.SetFocus;
end;
end;
Ejemplo de llamada:
Código:
procedure TForm1.Button1Click(Sender: TObject);
var
Pot: Double;
Fac: Longint;
begin
Pot:= Potencia(StrToFloat(EditX.Text),StrToInt(EditY.Text));
Fac:= Factorial(StrToInt(EditY.Text));
ShowMessage(FloatToStr(Pot)+' '+IntToStr(Fac));
end;
Con eso tenés las herramientas para solucionar el problema.
Nota: Como imagino que los valores de x e y son ingresados puse dos TEdit's para ello: EditX y EditY.
Saludos.