Advertisement
Ramiro-Pruis

Guia 3 - EJ16

Mar 24th, 2020
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.47 KB | None | 0 0
  1. program G03EJ16;
  2. var
  3.   km,lit:real;
  4.   pat:string[7];
  5.   salida:text;
  6.   letrasP,numerosP:integer;
  7. begin
  8.   assign(salida,'kilometros.txt');rewrite(salida);
  9.   repeat
  10.     write('Ingrese los kilometros recorrido(0 para finalizar): ');readln(km);
  11.     while km<0 do //Validacion para los kilometros recorridos//
  12.       begin
  13.         write('Ingrese un valor valido: ');readln(km);
  14.       end;
  15.     if km<>0 then
  16.       begin
  17.         write('Ingrese la patente: ');readln(pat);pat:=upcase(pat);
  18.            //validacion de Patente//
  19.         letrasP:=ord(pat[1])+ord(pat[2])+ord(pat[6])+ord(pat[7]);
  20.         numerosP:=ord(pat[3])+ord(pat[4])+ord(pat[5]);
  21.         while (letrasP<ord('A')*4) or (letrasP>ord('Z')*4) or (numerosP<ord('0')*3) or (numerosP>ord('9')*3) do
  22.           begin
  23.             writeln('Ingrese una patente valida: ');readln(pat);pat:=upcase(pat);
  24.             letrasP:=ord(pat[1])+ord(pat[2])+ord(pat[6])+ord(pat[7]);
  25.             numerosP:=ord(pat[3])+ord(pat[4])+ord(pat[5]);
  26.           end;
  27.             //Cree las variables para acortar la longitud de la funcion while//
  28.               //Esta forma fue la forma mas optima que se me ocurre//
  29.         write('Ingrese los litros consumidos: ');readln(lit);
  30.         while lit<0 do //Validacion para los litros//
  31.           begin
  32.             write('Ingrese un valor valido: ');readln(lit);
  33.           end;
  34.         write(salida,pat,' ');
  35.         writeln(salida,lit/km:0:2,'L/Km');
  36.       end;
  37.   until km=0;
  38.   close(salida);
  39. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement