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

 

 


Tema destacado: Guía rápida para descarga de herramientas gratuitas de seguridad y desinfección


  Mostrar Temas
Páginas: 1 [2]
11  Programación / Programación C/C++ / Números aleatorios sin repeticion en: 12 Abril 2013, 17:39 pm
Ayuda con este código, simplemente se me repite los números al azar, y eso es loq no quiero
Código
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. string profe[5];
  9. string materia[5][3];
  10. int salon[5][3];
  11. int rep;
  12. int i=0,j=0,k=0,l=0;
  13. srand(time(NULL));
  14. do{j=0;
  15. cout<<"Ingrese profesor No "<<i+1<<": ";
  16. cin>>profe[i];
  17. while(j!=3){
  18. cout<<"Ingrese materia #"<<j+1<<" del profesor "<<profe[i]<<": ";
  19. cin>>materia[i][j];
  20.  
  21. do{rep=true;
  22. salon[i][j]=rand()%15+301;
  23. if((i>0)||(j>0)){k=0;l=0;
  24. while((k=!i)&&(l!=j)){
  25. if(salon[i][j]==salon[k][l]){
  26. rep=false;}
  27. if(l==2){l=0;k++;}else{
  28. l++;}}}
  29. }while(rep!=true);
  30.  
  31. j++;}i++;
  32. }while(i!=5);
  33. i=0;
  34. cout<<"\n\nMaestro\tMateria\tSalon\n";
  35. while(i!=5){j=0;
  36. cout<<endl<<profe[i];
  37. while(j!=3){
  38. cout<<"\n\t"<<materia[i][j]<<"\t"<<salon[i][j];
  39. j++;}i++;}
  40. return 0;
  41. }

Modificado: es mas fácil leer el código utilizando el coloreado.
Páginas: 1 [2]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines