Ver Mensaje Individual
  #5 (permalink)  
Antiguo 30/11/2013, 22:03
Avatar de guzzano
guzzano
 
Fecha de Ingreso: julio-2010
Ubicación: Isla de Margarita
Mensajes: 162
Antigüedad: 13 años, 9 meses
Puntos: 13
Respuesta: Error con un array en proyecto final

Buenas, te acomodé un poco el código, dime si esto era lo que tratabas de hacer:

Código C++:
Ver original
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <ctime>
  4.  
  5. using namespace std;
  6.  
  7. bool serepita (int num, int numero[][9])
  8. {
  9.   for (int b = 0; b < 9; b++)
  10.   {
  11.     for(int c = 0; c < 9; c++)
  12.     {
  13.       if (num == numero[b][c])
  14.       {
  15.         return true;
  16.       }
  17.     }
  18.   }
  19.  
  20.   return false;
  21. }
  22.  
  23. int
  24. main (void)
  25. {
  26.   int s[9][9] =
  27.   {
  28.     1, 1, 0, 0, 1, 0, 0, 1, 0,  
  29.     1, 1, 0, 0, 0, 0, 0, 0, 1,  
  30.     0, 1, 1, 1, 0, 1, 1, 0, 0,  
  31.     0, 0, 0, 1, 1, 0, 1, 0, 1,
  32.     0, 1, 0, 0, 1, 0, 0, 1, 0,  
  33.     1, 0, 1, 0, 1, 1, 0, 0, 0,
  34.     0, 0, 1, 1, 0, 1, 1, 1, 0,  
  35.     1, 0, 0, 0, 0, 0, 0, 1, 1,  
  36.     0, 1, 0, 0, 1, 0, 0, 1, 1
  37.   };
  38.    
  39.   int elnumero;
  40.   int az;
  41.   int i = 0;
  42.   int j = 0;
  43.    
  44.   srand(time(NULL));
  45.  
  46.   for (; i < 9; i++)
  47.   {
  48.     for(j = 0; j < 9; j++)
  49.     {
  50.       if(s[i][j] == 1)
  51.       {
  52.         az = 1 + rand() % 9;
  53.         s[i][j] = az;
  54.       }
  55.     }
  56.   }
  57.  
  58.   for (i = 0; i < 9; i++)
  59.   {
  60.     for(j = 0; j < 9; j++)
  61.     {
  62.       elnumero = s[i][j];
  63.  
  64.       while (serepita(elnumero, s) != true)
  65.       {
  66.         s[i][j] = rand() % 9;  
  67.       }
  68.     }
  69.   }
  70.    
  71.   for (i = 0; i < 9; i++)
  72.   {
  73.     for(j = 0; j < 9; j++)
  74.     {
  75.       if(s[i][j] == 0)
  76.         cout << " º   º" << endl;
  77.       else
  78.         cout << " º " << s[i][j] << " º " << endl;
  79.     }
  80.    
  81.     cout << "\n\n" << endl;    
  82.   }    
  83.  
  84.   return EXIT_SUCCESS;
  85. }