soy superonprincipiante
que tiene de malo este codigo:
#include <iostream.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <conio.h>
#include <dos.h>
#include <string>
char a[4];
int b,c,d;
int main()
{
struct persona {
char nombre[70];
char tel[70];
}fulano[5];
for (b = 0; b<= 4; b++){
cout << endl;
cout <<"insetre nombre: ";
cin >>fulano[b].nombre;
cout <<"inserte telefono: ";
cin >>fulano[b].tel;
}
system ("CLS");
cout <<" Menu"<<endl;
cout <<" 1. Buscar por nombre"<<endl;
cout <<" 2. Buscar por Telefono"<<endl;
cout <<endl;
cout <<" Elegir ocion: ";
cin >> d;
if (d == 1){
system ("CLS");
cout << "Inserte nombre a buscar ";
cin >> a;
for (c = 0;c <= 4;c++){
if (fulano[c].nombre == a){
cout << fulano[c].nombre <<fulano[c].tel << endl;
}
}
}
}
#include <iostream.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <conio.h>
#include <dos.h>
#include <string>
char a[4];
int b,c,d;
int main()
{
struct persona {
char nombre[70];
char tel[70];
}fulano[5];
for (b = 0; b<= 4; b++){
cout << endl;
cout <<"insetre nombre: ";
cin >>fulano[b].nombre;
cout <<"inserte telefono: ";
cin >>fulano[b].tel;
}
system ("CLS");
cout <<" Menu"<<endl;
cout <<" 1. Buscar por nombre"<<endl;
cout <<" 2. Buscar por Telefono"<<endl;
cout <<endl;
cout <<" Elegir ocion: ";
cin >> d;
if (d == 1){
system ("CLS");
cout << "Inserte nombre a buscar ";
cin >> a;
for (c = 0;c <= 4;c++){
if (fulano[c].nombre == a){
cout << fulano[c].nombre <<fulano[c].tel << endl;
}
}
}
}
Las cadenas no se pueden comparar comparando las variables directamente. El nombre no se puede comparar
if ( fulano[c].nombre == a )
Debes comparar cadenas usando la función strcmp()
if ( strcmp (fulano[c].nombre, a) == 0 )
Se bueno.
if ( fulano[c].nombre == a )
Debes comparar cadenas usando la función strcmp()
if ( strcmp (fulano[c].nombre, a) == 0 )
Se bueno.
