trabalho escolar

04/04/2003

0

oi tudo bem,este é um trabalho para nota,e estou com alguns problemas,gostaria que vc desse uma olhada e visse onde eu estou errando,porque nos resultados as porcentagens não me parecem corretas,
desde já agradeço!!! abaixo do enunciado eu coloquei como eu fiz.


DETERMINAR AS POSSIBILIDADES DE OCORRENCIA DE RESULTADOS CARA E COROA NA SEQUENCIA DE 1000 LANÇAMENTOS VÁLIDOS DE 3 MOEDAS ,SENDO 1 DE R$ 0,25,1 DE R$ 0,50 E 1 DE R$ 1,00
AS MOEDAS SÃO EXTRAIDAS ALEATORIAMENTE DE UM RECIPIENTE.
APRESENTAR AO FINAL.
- ¬ DE MOEDAS DE 0,25 LANÇADAS
- ¬ DE MOEDAS DE 0,50 LANÇADAS
- ¬ DE MOEDAS DE 1,00 LANÇADAS

- ¬ DE RESULTADO CARA
MOEDAS DE 0,25
MOEDAS DE 0,50
MOEDAS DE 1,00

- ¬ DE RESULTADO COROA
MOEDAS DE 0,25
MOEDAS DE 0,50
MOEDAS DE 1,00

- ¬ DE LANÇAMENTOS INVÁLIDOS
--------------------------------------------------------------------------------------
procedure TForm1.Button1Click(Sender: TObject);
var
i : integer;
m25,m50,m1,rcaram25,rcaram50,rcaram1,rcoroam25,rcoroam50,rcoroam1:real;
vetor : array[0..5] of integer;
begin
for i := 0 to 1000 do
inc(vetor[random(6)]);
m25 := (vetor[0] + vetor[3])/ 100;//¬ DE MOEDAS DE 0,25 LANÇADAS
m50 := (vetor[1] + vetor[4])/ 100;//- ¬ DE MOEDAS DE 0,50 LANÇADAS
m1:= (vetor[2] + vetor[5])/ 100;//- ¬ DE MOEDAS DE 1,00 LANÇADAS
edit1.text:=floattostrf(m25,ffFixed,6,2);
edit2.text:=floattostrf(m50,ffFixed,6,2);
edit3.text:=floattostrf(m1,ffFixed,6,2);
//- ¬ DE RESULTADO CARA
rcaram25:= (vetor[0])/ 100;//MOEDAS DE 0,25
rcaram50:= (vetor[1])/ 100;//MOEDAS DE 0,50
rcaram1:= (vetor[2])/ 100;//MOEDAS DE 1,00
edit4.text:=FloatToStrF(rcaram25,ffFixed,6,2);

edit5.text:=floattostrf(rcaram50,ffFixed,6,2);
edit6.text:=floattostrf(rcaram1,ffFixed,6,2);

//- ¬ DE RESULTADO COROA


Anonymous

Anonymous

Responder

Posts

04/04/2003

Anonymous

Oi, acho que têm vários problemas. Fiz um exemplo da maneira mais simples possível e funcionou. Veja abaixo.

unit caracoroa;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
Edit6: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
moeda:Array[0..2] of Integer;
i,j:integer;
begin
Edit1.text:=´0´;Edit2.text:=´0´;Edit3.text:=´0´;Edit4.text:=´0´;
Edit5.text:=´0´;Edit6.text:=´0´;
randomize;
for j:=1 to 1000 do
begin
i:=0;
moeda[0]:=3;moeda[1]:=3;moeda[2]:=3;
i:=random(2);
moeda[random(3)]:=i;
if moeda[0]<>3 then
begin
if moeda[0]=0 then Edit1.text:=inttostr(strtoint(Edit1.text)+1);
if moeda[0]=1 then Edit4.text:=inttostr(strtoint(Edit4.text)+1);
end;
if moeda[1]<>3 then
begin
if moeda[1]=0 then Edit2.text:=inttostr(strtoint(Edit2.text)+1);
if moeda[1]=1 then Edit5.text:=inttostr(strtoint(Edit5.text)+1);
end;
if moeda[2]<>3 then
begin
if moeda[2]=0 then Edit3.text:=inttostr(strtoint(Edit3.text)+1);
if moeda[2]=1 then Edit6.text:=inttostr(strtoint(Edit6.text)+1);
end;

end;

end;

end.

Como você vê usei seis tedits e fui acumulando em cada um, sendo que o Edit1 e Edit4 correspondem à moeda de 0,25 por exemplo. Os Edits 2 e 5 à moeda de 0,50 e os Edits 3 e 6 à moeda de 1,00.

Abraços.


Responder

04/04/2003

Anonymous

Oi, acho que têm vários problemas. Fiz um exemplo da maneira mais simples possível e funcionou. Veja abaixo.

unit caracoroa;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
Edit6: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
moeda:Array[0..2] of Integer;
i,j:integer;
begin
Edit1.text:=´0´;Edit2.text:=´0´;Edit3.text:=´0´;Edit4.text:=´0´;
Edit5.text:=´0´;Edit6.text:=´0´;
randomize;
for j:=1 to 1000 do
begin
i:=0;
moeda[0]:=3;moeda[1]:=3;moeda[2]:=3;
i:=random(2);
moeda[random(3)]:=i;
if moeda[0]<>3 then
begin
if moeda[0]=0 then Edit1.text:=inttostr(strtoint(Edit1.text)+1);
if moeda[0]=1 then Edit4.text:=inttostr(strtoint(Edit4.text)+1);
end;
if moeda[1]<>3 then
begin
if moeda[1]=0 then Edit2.text:=inttostr(strtoint(Edit2.text)+1);
if moeda[1]=1 then Edit5.text:=inttostr(strtoint(Edit5.text)+1);
end;
if moeda[2]<>3 then
begin
if moeda[2]=0 then Edit3.text:=inttostr(strtoint(Edit3.text)+1);
if moeda[2]=1 then Edit6.text:=inttostr(strtoint(Edit6.text)+1);
end;

end;

end;

end.

Como você vê usei seis tedits e fui acumulando em cada um, sendo que o Edit1 e Edit4 correspondem à moeda de 0,25 por exemplo. Os Edits 2 e 5 à moeda de 0,50 e os Edits 3 e 6 à moeda de 1,00.

Abraços.


Responder

Assista grátis a nossa aula inaugural

Assitir aula

Saiba por que programar é uma questão de
sobrevivência e como aprender sem riscos

Assistir agora

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar