Foro de elhacker.net

Programación => Programación C/C++ => Mensaje iniciado por: Lucho1110 en 31 Julio 2016, 21:13 pm



Título: Buenas, me podrian brindar ayuda aca
Publicado por: Lucho1110 en 31 Julio 2016, 21:13 pm
seguí haciendo el codigo y lo termine con ayuda de varias paginas, el me compila, pero me arroja un problemita cuando deseo agregar mas personas, me salta el nombre o el telefono fijo o el grupo, no se que tengo mal, muchas gracias por la ayuda
Código
  1. #include <iostream>
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4. #include<string.h>
  5.  
  6. using namespace std;
  7.  
  8. struct agenda {
  9. char nom[15];
  10. int t_f;
  11. int t_m;
  12. char dir[30], email[40], grupos[12];
  13. } control[100];
  14. int cont=0;
  15.  
  16. void agregar();
  17. void buscar();
  18. void contactos();
  19.  
  20. main(){
  21. int opc;
  22.  
  23. do{
  24. system("cls");
  25.  
  26. cout<<"MENU:"<<endl;
  27. cout<<"1.Agregar"<<endl;
  28. cout<<"2.Buscar"<<endl;
  29. cout<<"3.Ver todos los contactos"<<endl;
  30. cout<<"4.Salir"<<endl;
  31.  
  32. cin>>opc;
  33.  
  34. switch(opc){
  35.  
  36. case 1:
  37. agregar();
  38. system("pause");
  39. break;
  40.  
  41. case 2:
  42. buscar();
  43. system("pause");
  44. break;
  45.  
  46. case 3:
  47. contactos();
  48. system("pause");
  49. break;
  50. }
  51. }while(opc!=4);
  52.  
  53. return 0;
  54. }
  55.  
  56. void agregar(){
  57. system("cls");
  58.  
  59. fflush(stdin);
  60. cout<<"Nombre de contacto:"<<cont+1<<endl;
  61. gets(control[cont].nom);
  62.  
  63. fflush(stdin);
  64. cout<<"\nTel\202fono fijo:";
  65. cin>>control[cont].t_f;
  66.  
  67. fflush(stdin);
  68. cout<<"\nTel\202fono m\242vil:";
  69. cin>>control[cont].t_m;
  70.  
  71. fflush(stdin);
  72. cout<<"\nDirecci\242n:";
  73. gets(control[cont].dir);
  74.  
  75. fflush(stdin);
  76. cout<<"\nE-mail:";
  77. gets(control[cont].email);
  78.  
  79. fflush(stdin);
  80. cout<<"\nGrupo:";
  81. gets(control[cont].grupos);
  82.  
  83. cont++;
  84.  
  85. }
  86.  
  87. void buscar(){
  88. char busca[15];
  89. int i;
  90.  
  91. system("cls");
  92.  
  93. fflush(stdin);
  94. cout<<"\nBuscar contacto\nIngrese el nombre del contacto:";
  95. gets(busca);
  96.  
  97. for(i=0;i<cont;i++){
  98. if(strcmpi(busca,control[i].nom)==0){
  99. cout<<"\nNombre: %s\n"<<control[i].nom;
  100. cout<<"Tel\202fono fijo: %d\n"<<control[i].t_f;
  101. cout<<"Tel\202fono m\242vil: %d\n"<<control[i].t_m;
  102. cout<<"Direcci\242n: %s\n"<<control[i].dir;
  103. cout<<"E-mail: %s\n"<<control[i].email;
  104. cout<<"Grupo: %s\n"<<control[i].grupos;
  105. }
  106. }
  107.  
  108. }
  109.  
  110. void contactos(){
  111. int aux, i, j;
  112. char auxc[50];
  113.  
  114. system("cls");
  115.  
  116. for(i=0;i<cont-1;i++){
  117. for(j=0;j<cont-1-i;j++){
  118. if(strcmp(control[j].nom,control[j+1].nom)>0){
  119.  
  120. strcpy(auxc,control[j].nom);
  121. strcpy(control[j].nom,control[j+1].nom);
  122. strcpy(control[j+1].nom,auxc);
  123.  
  124. aux = control[j].t_f;
  125. control[j].t_f = control[j+1].t_f;
  126. control[j+1].t_f = aux;
  127.  
  128. aux = control[j].t_m;
  129. control[j].t_m = control[j+1].t_m;
  130. control[j+1].t_m = aux;
  131.  
  132. strcpy(auxc,control[j].dir);
  133. strcpy(control[j].dir,control[j+1].dir);
  134. strcpy(control[j+1].dir,auxc);
  135.  
  136. strcpy(auxc,control[j].email);
  137. strcpy(control[j].email,control[j+1].email);
  138. strcpy(control[j+1].email,auxc);
  139.  
  140. strcpy(auxc,control[j].grupos);
  141. strcpy(control[j].grupos,control[j+1].grupos);
  142. strcpy(control[j+1].grupos,auxc);
  143. }
  144. }
  145. }
  146.  
  147. cout<<"\nAgenda.\n";
  148.  
  149. for(i=0;i<cont;i++){
  150. cout<<"\n%d.Nombre: %s\n"<<(i+1)<<control[i].nom;
  151. cout<<"Tel\202fono fijo: %d\n"<<control[i].t_f;
  152. cout<<"Tel\202fono m\242vil: %d\n"<<control[i].t_m;
  153. cout<<"Direcci\242n: %s\n"<<control[i].dir;
  154. cout<<"E-mail: %s\n"<<control[i].email;
  155. cout<<"Grupo: %s\n"<<control[i].grupos;
  156. }
  157.  
  158. }


[MOD] Yá tienes un hilo abierto con el mismo tema. Lee las Reglas del Foro.

https://foro.elhacker.net/programacion_cc/necesito_ayuda-t455839.0.html;msg2081456;topicseen#msg2081456

Tema cerrado.