Ver Mensaje Individual
  #2 (permalink)  
Antiguo 10/11/2011, 01:44
Avatar de s00rk
s00rk
 
Fecha de Ingreso: octubre-2010
Ubicación: Mexico
Mensajes: 238
Antigüedad: 13 años, 6 meses
Puntos: 48
Respuesta: Diferentes nombres en un ciclo while

Código C++:
Ver original
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <Windows.h>
  4.      
  5. using namespace std;
  6.  
  7. bool Existe(char arr[][60], char *nombre, int num);
  8.  
  9. int main()
  10. {
  11.     int num;
  12.     cout << "Cantidad de nombres a insertar: ";
  13.     cin >> num;
  14.     char arr[num][60];
  15.     char *nombre;
  16.     for(int x = 0; x < num; x++)
  17.     {
  18.             cout << "Ingresa Nombre: ";
  19.             cin >> nombre;
  20.             if(Existe(arr, nombre, num))
  21.             {
  22.                 cout << "El nombre ya se ha introducido anteriormente" << endl;
  23.                 x--;
  24.             }else{
  25.                   sprintf(arr[x],"%s",nombre);
  26.                   cout << "Nombre Insertado" << endl;
  27.             }
  28.     }
  29.     cout << endl << endl;
  30.     for(int x = 0; x < num; x++)
  31.     {
  32.             cout << arr[x] << endl;
  33.     }
  34.     cin.get();cin.get();
  35.     return 0;
  36. }
  37.  
  38. bool Existe(char arr[][60], char *nombre, int num)
  39. {
  40.      for(int x = 0; x < num; x++)
  41.      {
  42.              if(strcmp(arr[x], nombre) == 0)
  43.                                return true;
  44.      }
  45.      return false;
  46. }