Foros del Web » Programación para mayores de 30 ;) » Programación General »

[SOLUCIONADO] ¿Cómo incrementar un valor en Lazarus Pascal?

Estas en el tema de ¿Cómo incrementar un valor en Lazarus Pascal? en el foro de Programación General en Foros del Web. Buen día, tengo un problema no logro incrementar el valor de unas variables en Pascal. Tengo este código para generar dos números aleatorios: @import url("http://static.forosdelweb.com/clientscript/vbulletin_css/geshi.css"); ...
  #1 (permalink)  
Antiguo 04/11/2012, 08:45
Avatar de ARICARRARO  
Fecha de Ingreso: diciembre-2010
Ubicación: México
Mensajes: 227
Antigüedad: 13 años, 3 meses
Puntos: 10
Pregunta ¿Cómo incrementar un valor en Lazarus Pascal?

Buen día, tengo un problema no logro incrementar el valor de unas variables en Pascal.

Tengo este código para generar dos números aleatorios:
Código pascal:
Ver original
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   azar1,azar2:integer;
  4. begin
  5.   randomize;
  6.   azar1:=random(101)*2;
  7.   azar2:=random(101)*3;
  8.   Edit4.Text:=inttostr(azar1);
  9.   Edit5.Text:=inttostr(azar2);
  10. end;

Ahora tengo este código para comprobar si el valor introducido por el usuario es igual a la suma de esos dos números aleatorios:


Código pascal:
Ver original
  1. procedure TForm1.Button3Click(Sender: TObject);
  2. var
  3.   resultado:integer;
  4.   suma:integer;
  5.   elemento:Elementos;
  6. begin
  7.   elemento.aciertos:=0;
  8.   elemento.fallos:=0;
  9.   elemento.intentos:=0;
  10.   resultado:=strtoint(InputBox ('Aviso','Resultado:',''));
  11.   suma:=strtoint(Edit4.Text) + strtoint(Edit5.Text);
  12.  
  13.   if suma = resultado then
  14.     begin
  15. {aqui deberia incrementarse el valor}
  16.     elemento.aciertos:=elemento.aciertos+1;
  17.     elemento.intentos:=elemento.intentos+1;
  18.  
  19.     Edit1.Text:=inttostr(elemento.aciertos);
  20.    Edit2.Text:=inttostr(elemento.fallos);
  21.    Edit3.Text:=inttostr(elemento.intentos);
  22.     end
  23.   else
  24.      begin
  25. {aqui deberia incrementarse el valor}
  26.      elemento.fallos:=elemento.fallos+1;
  27.     elemento.intentos:=elemento.intentos+1;
  28.  
  29.      Edit1.Text:=inttostr(elemento.aciertos);
  30.    Edit2.Text:=inttostr(elemento.fallos);
  31.    Edit3.Text:=inttostr(elemento.intentos);
  32.      end
  33.  
  34. end;


Donde elemento es una variable tipo record:

Código pascal:
Ver original
  1. type
  2.  
  3.     Elementos=record
  4.     aciertos:integer;
  5.     fallos:integer;
  6.     intentos:integer;
  7.     end;

Espero puedan ayudarme, gracias.
  #2 (permalink)  
Antiguo 15/11/2012, 09:26
Avatar de ARICARRARO  
Fecha de Ingreso: diciembre-2010
Ubicación: México
Mensajes: 227
Antigüedad: 13 años, 3 meses
Puntos: 10
Respuesta: ¿Cómo incrementar un valor en Lazarus Pascal?

Ya lo resolví dejo el código:

Código pascal:
Ver original
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;
  9.  
  10. type
  11.  
  12.   Elementos=record
  13.     aciertos:integer;
  14.     fallos:integer;
  15.     intentos:integer;
  16.     end;
  17.  
  18.   { TForm1 }
  19.  
  20.   TForm1 = class(TForm)
  21.     Button1: TButton;
  22.     Button2: TButton;
  23.     Edit1: TEdit;
  24.     Edit2: TEdit;
  25.     Edit3: TEdit;
  26.     Edit4: TEdit;
  27.     Edit5: TEdit;
  28.     Edit6: TEdit;
  29.     Label1: TLabel;
  30.     Label2: TLabel;
  31.     Label3: TLabel;
  32.     Label4: TLabel;
  33.     Label5: TLabel;
  34.     Label6: TLabel;
  35.     procedure Button1Click(Sender: TObject);
  36.     procedure Button2Click(Sender: TObject);
  37.     procedure FormCreate(Sender: TObject);
  38.   private
  39.     { private declarations }
  40.   public
  41.     { public declarations }
  42.   end;
  43.  
  44. var
  45.   Form1: TForm1;
  46.   elemento:Elementos;
  47.  
  48. implementation
  49.  
  50. {$R *.lfm}
  51.  
  52. { TForm1 }
  53.  
  54. procedure TForm1.FormCreate(Sender: TObject);
  55.  
  56. begin
  57.  
  58. elemento.aciertos:=0;
  59. elemento.fallos:=0;
  60. elemento.intentos:=0;
  61.  
  62. end;
  63.  
  64. procedure TForm1.Button1Click(Sender: TObject);
  65. var
  66.   alea1,alea2:integer;
  67. begin
  68.     randomize;
  69.     alea1:=random(102)-25;
  70.     alea2:=random(102)-22;
  71.     Edit1.Text:=inttostr(alea1);
  72.     Edit2.Text:=inttostr(alea2);
  73.  
  74.  
  75. end;
  76.  
  77. procedure TForm1.Button2Click(Sender: TObject);
  78. var
  79.   numero,suma:integer;
  80.  
  81. begin
  82.     numero:=strtoint(InputBox('Introduce resultado','Aqui:',''));
  83.     {ShowMessage('Introduciste: '+ inttostr(numero));  }
  84.     suma:=strtoint(Edit1.Text)+strtoint(Edit2.Text);
  85.  
  86.   if suma = numero then
  87.     begin
  88. {aqui deberia incrementarse el valor}
  89.     elemento.aciertos:=elemento.aciertos+1;
  90.     elemento.intentos:=elemento.intentos+1;
  91.  
  92.     Edit4.Text:=inttostr(elemento.aciertos);
  93.    Edit5.Text:=inttostr(elemento.fallos);
  94.    Edit6.Text:=inttostr(elemento.intentos);
  95.     end
  96.   else
  97.      begin
  98. {aqui deberia incrementarse el valor}
  99.      elemento.fallos:=elemento.fallos+1;
  100.     elemento.intentos:=elemento.intentos+1;
  101.  
  102.      Edit4.Text:=inttostr(elemento.aciertos);
  103.    Edit5.Text:=inttostr(elemento.fallos);
  104.    Edit6.Text:=inttostr(elemento.intentos);
  105.      end
  106.  
  107.  
  108.  
  109.  
  110. end;
  111.  
  112. end.

Etiquetas: incrementar, pascal, registros, variables
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 14:08.