Dev - C++ - ayuda con punteros y classes

 
Vista:

ayuda con punteros y classes

Publicado por leonardo (8 intervenciones) el 02/09/2014 11:11:16
hola necesito que la variable "za1" sume de a 10 cada ves que se repita el bucle. (tengo q usar classes si o si)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <allegro.h>
 
 
void init();
void deinit();
 
class contador{
 
   public:
 
        int tiempos;
        int zetas;
 
          contador (int tiempos, int zetas){
 
 
                              zetas=zetas+tiempos;
                                                          }
 
 
               };
 
 
 
int main() {
	init();
 
bool a1=true;
bool a2=true;
int za1=0;
int za2=0;
int tiempo=10;
 
	while (!key[KEY_ESC]) {
	contador cuada1(tiempo,za1);
 
textprintf_ex(screen,font,20,20, 0x060BB3, -1,"za1 es: ""%d",za1);
	}
 
	deinit();
	return 0;
}
 
 
END_OF_MAIN()
 
void init() {
	int depth, res;
	allegro_init();
	depth = desktop_color_depth();
	if (depth == 0) depth = 32;
	set_color_depth(depth);
	res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
	if (res != 0) {
		allegro_message(allegro_error);
		exit(-1);
	}
 
	install_timer();
	install_keyboard();
	install_mouse();
	/* add other initializations here */
}
 
void deinit() {
	clear_keybuf();
	/* add other deinitializations here */
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de vangodp
Val: 73
Ha disminuido 1 puesto en Dev - C++ (en relación al último mes)
Gráfica de Dev - C++

ayuda con punteros y classes

Publicado por vangodp (287 intervenciones) el 03/09/2014 02:00:03
no se si te sirve pero aqui te dejo aun que recortado por que no uso allegro. Ademas su pregunta es como hacer para sumar 10 en cada pasada a za1..pues aquí va:
http://codepad.org/yAHE5XXn
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>
using namespace std;
 
 
class contador {
    public:
        contador() {}
        ~contador() {}
        void add ( int unTiempo, int &unaZeta ) { unaZeta += unTiempo; }
 
 
};
 
 
int main () {
    int i        = 0;
    int za1      = 0;
    int tiempo   = 10;
 
    contador miContador;
 
    while ( i < 10 ) {
 
        miContador.add ( tiempo, za1 ); //za1 pasado por referencia
        cout << za1 << endl;
        i++;
    }
 
 
    cin.ignore();
    return 0;
}

Si no te parece bien explícate algo mejor que quieres hacer y intentamos hacer algo mas efectivo ;)
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar