Jump to content

Ajuda!!! - Simulação da Oscilação de um título na Bolsa de Valores


d10g0l1r1
 Share

Recommended Posts

Este programa deve ler o valor inicial de um título numa bolsa de volores e depois fazer de forma aleatória 30 vezes um amuento ou diminuição de 0.01. É necessário usar funções e procedimentos.

Bem, estou a precisar de ajuda. Se alguém me pudesse corrigir o seguinte código ficaria muito agradecido:

program bolsa (input,output);
var
r:integer;
valorinicial:integer;
valorbolsa:real;
c:integer;

function naleatorio:integer;
begin
  randomize;
  r:=random(100)+1;
  naleatorio:=r;
end;

function repet(r:integer):real;
begin
  if (r>0) and (r<51) then
   repet:=0.01
  else
   if (r>51) and (r<101) then
    repet:=-0.01;
end;

procedure final;
begin
  for c:=1 to 30 do
   begin
    valorbolsa:=valorinicial+repet(naleatorio);
    writeln (valorbolsa:0:2);
   end;
end;

begin
naleatorio;
writeln ('Qual o valor inicial?');
readln (valorinicial);
final;
writeln (valorbolsa:0:2);
readln;
end.

Muito obrigado!!! Hasta 😞

Link to comment
Share on other sites

Epa o problema éque eu não consigo fazer aleatoriamente (30 vezes) osimulação do aumento ou diminuiçãodo tíyulo (em 0.01). Se copiarem o programa para pascal verão o problema.

Não tenho Pascal instalado para testar, mas posso tentar ajudar.

Uma das primeiras coisas que vejo que devem ser eliminadas são as variáveis globais, isso é só corda para um tipo se enforcar, além de não permitir certos tipos de optimização por parte dos compiladores.

Depois, o teu problema é que não faz as 30 vezes ou não faz a oscilação?

10 REM Generation 48K!
20 INPUT "URL:", A$
30 IF A$(1 TO 4) = "HTTP" THEN PRINT "400 Bad Request": GOTO 50
40 PRINT "404 Not Found"
50 PRINT "./M6 @ Portugal a Programar."

 

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
 Share

×
×
  • 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.