elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Rompecabezas de Bitcoin, Medio millón USD en premios


  Mostrar Temas
Páginas: [1]
1  Programación / Programación C/C++ / Duda acerca de matriz en c++ en: 19 Mayo 2014, 04:23 am
Hola a todos mi nombre es Laura y soy nueva por aquí, espero que todos estén bien. Mi duda es la siguiente yo quiero crear una matriz con ciertos elementos. Luego de llenarla quiero poder un elemento de mi matriz posición por posición según lo que ingrese el usuario, sea norte, sur, este, oeste, para así ir acumulando un puntaje. Yo cree el siguiente código pero no me funciona y no se que estoy haciendo mal. Disculpen la molestias y entiendan que soy principiante por lo que debo de tener los errores mas estúpidos, solo les muestro el norte porque mi código esta hecho un desastre y es muy largo, y como siempre se repite lo mismo quiero saber que tengo mal y así poder arreglarlo en los demás. Gracias de antemano, y sean un poco pacientes todavía soy principiante.

Código
  1. #include <iostream>
  2. #include <string>
  3. char matriz[20][20];
  4. using namespace std;
  5. //----------------------------------------------------------------------
  6. float Puntaje(int x, int y){
  7. float Pts;
  8. if (matriz[x][y]=='$'){
  9. Pts=1.0;
  10. }else if (matriz[x][y]=='%'){
  11. Pts=1.5;
  12. }else if (matriz[x][y]=='&'){
  13. Pts=2.0;
  14. }
  15. return Pts;
  16. }
  17. //----------------------------------------------------------------------
  18. void Mover_posicion( int fil, int col, char matriz[][20]){
  19. bool estado=false;
  20. int i,j,c,pasos,x,y,l,m,Ac;
  21. string mov;
  22. do{
  23. for( i=0;i<fil;i++){
  24. for( j=0;j<col;j++){
  25. if(matriz[i][j]=='I'){
  26. x=i;
  27. y=j;
  28. }
  29. if(matriz[i][j]=='F'){
  30. l=i;
  31. m=j;
  32. }
  33. }
  34.    }
  35.    cin>>mov>>pasos;
  36.  
  37.    for(c=0;c<pasos;c++){
  38. if(mov=="N"){
  39.  
  40.    if((x-pasos) < 0){
  41. Ac=Ac + Puntaje(x,y);
  42.    if(matriz[x][y]==matriz[l][m]){
  43.  for (i = 0; i < fil; i++){
  44.        for ( j = 0; j < col; j++)
  45.           cout << matriz[i][j] << " ";
  46.        cout << endl;  
  47.    }
  48. }else{  
  49.         matriz[x][y] = matriz[x][y];
  50.            matriz[x][y] = '#';
  51.  
  52.             if(matriz[i][j]=='I'  && matriz[x][y]!='|'  ){
  53.  
  54. for (x = 0; x < fil; x++){
  55.        for ( y = 0; y < col; y++)
  56.           cout << matriz[x][y] << " ";
  57.           cout << endl;
  58.  
  59.         }
  60.         }else if(matriz[x--][y]!='|'){
  61.  
  62. for (i = 0; i < fil; i++)
  63.    {
  64.        for ( j = 0; j < col; j++)
  65.           cout << matriz[i][j] << " ";
  66.        cout << endl;  
  67.    }
  68.    }
  69. }
  70. }
  71. x--;
  72. }  
  73. }
  74. if(matriz[x][y]==matriz[l][m]){
  75. estado=true;
  76. }
  77.  
  78.  
  79.    }while(estado!=true);
  80.    cout<<"Ha llegado"<<"su acumulado es:"<<Ac<<endl;
  81. }
  82. //----------------------------------------------------------------------
  83. int main(){
  84. int fil,col,i,j;
  85.  
  86. cout<<"Ingrese filas y columnas"<<endl;
  87. cin>>fil>>col;
  88.  
  89. for( i=0;i<fil;i++){
  90. for( j=0;j<col;j++){          
  91. do{
  92.        cin >> matriz[i][j];
  93.  
  94. }while(matriz[i][j]!='I' && matriz[i][j]!='F' && matriz[i][j]!='$' && matriz[i][j]!='&' && matriz[i][j]!='|' && matriz[i][j]!='%');
  95. }
  96. }    
  97. Mover_posicion( fil, col, matriz);
  98. }
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines