Dev - C++ - Error de variable

 
Vista:

Error de variable

Publicado por Erick S.A (1 intervención) el 12/06/2014 19:08:32
Hola amigos necesito un apoyo, estoy haciendo un buscaminas con ficheros, pero no me compila, aparece un error dejo el codigo.

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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
//#include <iostream.h>     
#include <iostream>
#include <stdlib.h>
//#include <iomanip.h>   
#include <iomanip>
#include <ctime>
 
 
using std::cout;
using std::cin;
using std::endl;
 
 
const int FILAS=10;
const int COLUMNAS=10;
const int PORC_MINIMO=20;
const int PORC_MAXIMO=30;
const int MIN_MINAS=PORC_MINIMO*(FILAS*COLUMNAS)/100;
const int MAX_MINAS=PORC_MAXIMO*(FILAS*COLUMNAS)/100;
 
 
 
enum Estado{DESCUBIERTA,INTERROGACION,MINA,CUBIERTA,POR_EXPANDIR};
 
struct Celda{
    char valor;
    Estado est;
};
 
typedef Celda Suelo[FILAS] [COLUMNAS];
 
struct Campo{
    Suelo s;
    int nminas;
    int ncubiertas;
};
 
int aleatorio(int max){
    return int(double(rand())*max/(RAND_MAX+1.0));
}
 
//definimos las funciones y procedimientos que utilizaremos
 
void vaciar(Campo &cmp){
    cmp.nminas=0;
    cmp.ncubiertas=FILAS*COLUMNAS;
    for (int i=0;i<FILAS;i++){
        for (int k=0;k<COLUMNAS;k++){
                cmp.s[k].valor=' ';
                cmp.s[k].est=CUBIERTA;
        }
    }
}
 
void generar_aleatorio(Campo &cmp,int nelm){
    int x,y;
    while (nelm>0){
        x=aleatorio(FILAS);
        y=aleatorio(COLUMNAS);
        if (cmp.s
[y].valor!='M'){
            cmp.s
[y].valor='M';
            nelm--;
        }
    }
    cmp.nminas=nelm;
}
 
bool CasillaCorrecta(int f,int c){
    return (f>=0)&&(f<FILAS)&&(c>=0)&&(c<COLUMNAS);
}
 
int contar_vecinos(const Campo &cmp,int f,int c){
    int cont=0,i,k;
    for(i=f-1;i<=f+1;i++){
        for(k=c-1;k<=c+1;k++){
                if (CasillaCorrecta(i,k)&&(cmp.s[k].valor=='M'))
{
                    cont++;
               }
        }
    }
    return cont;
}
 
void generar_vecinos(Campo &cmp){
    int i,k,cont;
    for(i=0;i<FILAS;i++){
        for(k=0;k<COLUMNAS;k++){
                if(cmp.s[k].valor==' '){
                   cont=contar_vecinos(cmp,i,k);
                   if(cont>0){
                      cmp.s[k].valor=cont+'0';
                   }
                }
        }
    }
}
 
void dibujar(const Campo cmp){
    int i,k;
    cout<<endl<<"Cubiertas: "<<cmp.ncubiertas<<endl;
    cout<<endl<<" ";
    for (i=0;i=COLUMNAS;i++){
        cout<<i%10;
    }
    cout<<endl<<" ";
    for(i=0;i<COLUMNAS;i++){
        cout<<"-";
    }
    cout<<endl;
    for(i=0;i<FILAS;i++){
        cout<<i%10<<"|";
        for(k=0;k<COLUMNAS;k++){
                switch (cmp.s[k].est){
                                case DESCUBIERTA:cout<<cmp.s[k].valor;break;
                                case INTERROGACION:cout<<"?";break;
                                case MINA:cout<<"M";break;
                                default:cout<<".";
                }
        }
        cout<<endl;
    }
}
void dibujar_solucion(const Campo cmp){
    int i,k;
    cout<<endl<<" ";
    for(i=0;i<COLUMNAS;i++){
        cout<<i%10;
    }
    cout<<endl<<" ";
    for(i=0;i<COLUMNAS;i++){
        cout<<"-";
    }
    cout<<endl;
    for(i=0;i<FILAS;i++){
        cout<<i%10<<"|";
        for(k=0;k<COLUMNAS;k++){
                cout<<cmp.s[k].valor;
        }
        cout<<endl;
    }
}
 
void expandir_a_vecinos(Campo &cmp,int f,int c,bool &hay_expansion){
    int i,k;
    hay_expansion=false;
    for(i=f-1;i<=f+1;i++){
        for(k=c-1;k<=c+1;k++){
                if (CasillaCorrecta(i,k)&&cmp.s[k].est!=DESCUBIERTA){
                                hay_expansion=true;
                                if (cmp.s[k].valor==' '){
                                    cmp.s[k].est=POR_EXPANDIR;
                                }else{
                                    cmp.s[k].est=DESCUBIERTA;
                                    cmp.ncubiertas--;
                                }
                }
        }
    }
}
 
void descubrir_vecinos_sin_minas (Campo &cmp,int ff,int cc){
    int i,k;
    bool hay_expansion,exp;
    expandir_a_vecinos (cmp,ff,cc,hay_expansion);
    while (hay_expansion){
        hay_expansion=false;
        for (i=0;i<FILAS;i++){
                for (k=0;k<COLUMNAS;k++){
                                if(cmp.s[k].est==POR_EXPANDIR){
                                   cmp.s[k].est=DESCUBIERTA;
                                   cmp.ncubiertas--;
                                   expandir_a_vecinos(cmp,i,k,exp);
                                   hay_expansion=hay_expansion||exp;
                                }
                }
        }
    }
}
 
void descubrir(Campo &cmp,int f,int c,bool &explosion){
    cmp.s[f][c].est=DESCUBIERTA;
    cmp.ncubiertas--;
    if (cmp.s[f][c].valor=='M'){
        explosion=true;
    }else if(cmp.s[f][c].valor==' '){
        descubrir_vecinos_sin_minas(cmp,f,c);
        explosion=false;
    }else{
        explosion=false;
    }
}
 
void marcar(Campo &cmp,int f,int c,const Estado e){
    cmp.s[f][c].est=e;
}
 
void leer_operacion(char &cod,int &f,int &c){
    do{
        cout<<endl<<"Introduce codigo[d,m,?,s]: ";
        cin>>cod;
    }while((cod!='d')&&(cod!='m')&&(cod!='?')&&(cod!='s'));
 
    if(cod!='s'){
        do{
                cout<<"Introduce fila: ";
                cin>>f;
        }while((f<0)||(f>=FILAS));
        do{
                cout<<"Introduce columna: ";
                cin>>c;
        }while((c<0)||(c>=COLUMNAS));
    }
}
 
void jugar(){
    Campo cmp;
    char op,nivel;
    int f,c,minas=3;
    bool explosion=false,ganar=false,salir=false;
 
    do{
        cout<<endl<<"Introduce nivel juego[f=facil,d=dificil,m=leer minas]; ";
                cin>>nivel;
        }while ((nivel!='f')&&(nivel!='d')&&(nivel!='m'));
        switch (nivel){
                case 'f':minas=MIN_MINAS;break;
                case 'd':minas=MAX_MINAS;break;
                case 'm':cout<<"Introduce minas: ";
                         cin>>minas;
        }
        vaciar(cmp);
        generar_aleatorio(cmp,minas);
        generar_vecinos(cmp);
        do{
                dibujar(cmp);
                leer_operacion(op,f,c);
                switch (op){
                                case 'd':descubrir(cmp,f,c,explosion);break;
                                case 'm':marcar(cmp,f,c,MINA);break;
                                case '?':marcar(cmp,f,c,INTERROGACION);break;
                                case 's':salir=true;
                }
                if (cmp.ncubiertas==minas){
                                ganar=true;
                }
        }while ((!explosion)&&(!ganar)&&(!salir));
        if (explosion){
            cout<<endl<<"BOOOOMM!!!! HAS PERDIDO"<<endl;
        }else if(ganar){
                cout<<endl<<"BIEN HAS GANADO"<<endl;
        }else{
                cout<<endl<<"TE HAS RENDIDO"<<endl;
        }
        dibujar_solucion(cmp);
    }
 
 
 
 
int main (){
 
 
    srand(time(0));
    cout<<endl<<"Juego: BUSCAMINAS"<<endl<<endl;
    jugar();
    system("PAUSE");
    return 0;
}

el error es en el modulo vaciar campo.. pero tambien en los VOid porque?
cmp.s[k].valor=' ';

D:\Programacion\C++\modulo1-ejec.cpp In function `void vaciar(Campo&)':
49 D:\Programacion\C++\modulo1-ejec.cpp request for member `valor' in `cmp->Campo::s[k]', which is of non-class type `Celda[10]'
50 D:\Programacion\C++\modulo1-ejec.cpp request for member `est' in `cmp->Campo::s[k]', which is of non-class type `Celda[10]'
D:\Programacion\C++\modulo1-ejec.cpp In function `void generar_aleatorio(Campo&, int)':
61 D:\Programacion\C++\modulo1-ejec.cpp request for member `valor' in `cmp->Campo::s[y]', which is of non-class type `Celda[10]'
63 D:\Programacion\C++\modulo1-ejec.cpp request for member `valor' in `cmp->Campo::s[y]', which is of non-class type `Celda[10]'
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