Jump to content

Randomize


Hypr

Recommended Posts

boas [] antes de mais desculpem abrir novo topico ..... uma duvida na estrutura randomize quando o utilizador define o numero de tentativas k ker utilizar ao gerar o valor ao calha qual e o a fase em k colocamos isso ?? e que nao consigo pensar

sera tipo

....

Randomize;

    valor := Random(y);

....

em k o y e o valor e gera mas eu kero kolocar e o numero de tentativas ...

obd e desculpem a minah ignoranca xD

Link to comment
Share on other sites

{Programa em que o utilizador deve acertar num número aleatório gerado pelo computador num determinado número de tentativas.}

Program Projecto;

uses wincrt;

var
  Tent, cont              : byte;
  Aleat, NAleat, valor    : integer;
  OP                      : char;

begin
  NAleat:= 101;
  Tent:= 10;

  Randomize;
  Aleat:= Random(NAleat);

  gotoxy(25,10);
  writeln('--Qual é o Número?!--');
  readkey;

  Repeat
    clrscr;
    gotoxy(12,1);
    writeln(' ____________________________________________ ');
    gotoxy(12,2);
    writeln('|--------------------MENU--------------------|');
    gotoxy(12,3);
    writeln('|1 -> Alterar nº máximo a gerar--------------|');
    gotoxy(12,4);
    writeln('|2 -> Alterar nº máximo de tentativas--------|');
    gotoxy(12,5);                                      
    writeln('|3 -> Jogar----------------------------------|');
    gotoxy(12,6);
    writeln('|0 -> Sair-----------------------------------|');
    writeln('Opção:[?]');
    gotoxy(8,7);
    OP:= readkey;
     
    Case OP of
      '1' : begin
              clrscr;
              write('Número máximo a gerar...');
              readln(NAleat);
              if NAleat>1
              then begin
                     Randomize;
                     Aleat:= Random(NAleat);
                   end
              else begin
                     writeln('Número Inferior a 1!!');
                     readkey;
                   end;
            end;
      '2' : begin
              clrscr;
              write('Número de Tentativas...');
              readln(Tent);
              if Tent<=1
                then begin
                       writeln('O número de tentativas tem de ser superior a 0!');
                       readkey;
                     end;
            end;
      '3' : begin
              clrscr;

              Randomize;
              Aleat:= Random(NAleat);

              for cont:=0 to Tent do Begin

                Repeat                                      
                  writeln('Qual é o número? ');
                  readln(valor);
                                
                  if valor=Aleat
                    then begin
                           clrscr;
                           writeln('Parabéns!!! Acertou!!!');
                           writeln('Número = ',Aleat);
                         end
                    else if valor > Aleat
                           then writeln(valor,' é superior ao número!')
                           else writeln(valor,' é inferior ao número!');

                  writeln;

                  cont:= cont+1;

                until (cont=Tent) OR (valor=Aleat);
                                
              end;

              if (cont= Tent) AND (valor<>Aleat)
                then writeln('Número = ',Aleat);

              readkey;

            end;
    
    end;

  until UpCase(OP)= '0';

  clrscr;



  gotoxy(1,25);
  write('Prima tecla para sair...');
  readkey;
  donewincrt;
  
end.

--------------------------------------------------

ai tem um joguinho xD espero que ajude alguem xD

Edit: M6 modificou a mensagem original com GeSHi.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.