Foro de elhacker.net

Programación => Programación C/C++ => Mensaje iniciado por: programador10 en 28 Abril 2011, 19:39 pm



Título: FUNCIONES Y PROCEDIMIENTO
Publicado por: programador10 en 28 Abril 2011, 19:39 pm

BUENAS TARDE








#include <cstdlib>
#include <iostream>

using namespace std;

void leer(int,int,int);
void operacion(int ,int ,int );



int main(int argc, char *argv[])
{   
    int edad1,nac1,act1;
   
   leer(edad1,nac1,act1);
   operacion(edad1,nac1,act1);
   
                     
    system("PAUSE");
    return EXIT_SUCCESS;
}

void leer(int &edad,int &nac,int &act)
{   
             
     cout<<"ingrese Edad"<<endl;
     cin>>edad;
     cout<<"ingrese Año de Nacimiento"<<endl;
     cin>>nac;
     cout<<"ingrese Año Actual"<<endl;
     cin>>act;     
       
}

void operacion(int &edad,int &nac,int &act)
{   
     cout<<"Bueno el tendras "<<(act-nac+edad)<<endl;         
     cin>>edad;
     cout<<edad;
     
   }


Título: Re: FUNCIONES Y PROCEDIMIENTO
Publicado por: El_Java en 28 Abril 2011, 19:42 pm
Y que nos quieres decir con esto?

Pd. para codigo usa etiquetas GeSHI


Título: Re: FUNCIONES Y PROCEDIMIENTO
Publicado por: programador10 en 28 Abril 2011, 19:45 pm
hola  gracias ... pero DONDE   ME INFORMO PARA PODER  postear de la mejor forma "EN ESTE FORO" gracias.


Título: Re: FUNCIONES Y PROCEDIMIENTO
Publicado por: leogtz en 28 Abril 2011, 19:50 pm
Solo escribe correctamente, y si quieres poner un código, seleccionalo y elige GeShi en el editor de mensajes, ahí seleccionas el lenguaje que quieras y ya.


Título: Re: FUNCIONES Y PROCEDIMIENTO
Publicado por: programador10 en 28 Abril 2011, 19:51 pm

Buenas TArdes El Siguiente codigo no me compila
Código
  1. #include <cstdlib>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. void leer(int,int,int);
  7. void operacion(int ,int ,int );
  8.  
  9.  
  10.  
  11. int main(int argc, char *argv[])
  12. {  
  13.    int edad1,nac1,act1;
  14.  
  15.   leer(edad1,nac1,act1);
  16.   operacion(edad1,nac1,act1);
  17.  
  18.  
  19.    system("PAUSE");
  20.    return EXIT_SUCCESS;
  21. }

y no comprendo por que no compila.
en la parte inferior me sale las siguistes obsevaciones.
  

  [Linker error] undefined reference to `leer(int, int, int)'
  [Linker error] undefined reference to `operacion(int, int, int)'
  ld returned 1 exit status



espero  SU AYUDA .!GRACIAS!





Título: Re: FUNCIONES Y PROCEDIMIENTO
Publicado por: programador10 en 28 Abril 2011, 19:53 pm
Código
  1. #include <cstdlib>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. void leer(int,int,int);
  7. void operacion(int ,int ,int );
  8.  
  9.  
  10.  
  11. int main(int argc, char *argv[])
  12. {  
  13.    int edad1,nac1,act1;
  14.  
  15.   leer(edad1,nac1,act1);
  16.   operacion(edad1,nac1,act1);
  17.  
  18.  
  19.    system("PAUSE");
  20.    return EXIT_SUCCESS;
  21. }
  22.  
  23. void leer(int &edad,int &nac,int &act)
  24. {    
  25.  
  26.     cout<<"ingrese Edad"<<endl;
  27.     cin>>edad;
  28.     cout<<"ingrese Año de Nacimiento"<<endl;
  29.     cin>>nac;
  30.     cout<<"ingrese Año Actual"<<endl;
  31.     cin>>act;    
  32.  
  33. }
  34.  
  35. void operacion(int &edad,int &nac,int &act)
  36. {    
  37.     cout<<"Bueno el tendras "<<(act-nac+edad)<<endl;          
  38.     cin>>edad;
  39.     cout<<edad;
  40.  
  41.   }
  42.  


Título: Re: FUNCIONES Y PROCEDIMIENTO
Publicado por: leogtz en 28 Abril 2011, 19:59 pm
Fijate que en el prototipo de la función leer(), no coinciden los parámetros con la definición después.

Debería ser así:

Código
  1. void leer(int&,int&,int&);
  2. void operacion(int &,int &,int &);
  3.  

Código
  1. #include <cstdlib>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. void leer(int&,int&,int&);
  7. void operacion(int &,int &,int &);
  8.  
  9. int main(int argc, char *argv[])
  10. {
  11.    int edad1,nac1,act1;
  12.  
  13.   leer(edad1,nac1,act1);
  14.   operacion(edad1,nac1,act1);
  15.  
  16.    system("pause");
  17.    return EXIT_SUCCESS;
  18. }
  19.  
  20. void leer(int &edad,int &nac,int &act)
  21. {
  22.  
  23.     cout<<"ingrese Edad"<<endl;
  24.     cin>>edad;
  25.     cout<<"ingrese Año de Nacimiento"<<endl;
  26.     cin>>nac;
  27.     cout<<"ingrese Año Actual"<<endl;
  28.     cin>>act;
  29.  
  30. }
  31.  
  32. void operacion(int &edad,int &nac,int &act)
  33. {
  34.     cout<<"Bueno el tendras "<<(act-nac+edad)<<endl;
  35.     cin>>edad;
  36.     cout<<edad;
  37. }
  38.  


Título: Re: FUNCIONES Y PROCEDIMIENTO
Publicado por: programador10 en 28 Abril 2011, 20:05 pm
disculpa podrias especificar mejor en donde esta mi error. GRACIAS ;)    :huh:


Título: Re: FUNCIONES Y PROCEDIMIENTO
Publicado por: leogtz en 28 Abril 2011, 20:09 pm
Tu lo tenías así:

Código
  1. void leer(int,int,int);
  2. void operacion(int ,int ,int );

Y debe ser así:

Código
  1. void leer(int&,int&,int&);
  2. void operacion(int &,int &,int &);

C++ tiene sobrecarga de funciones, por lo que el procedimiento:

Código
  1. void leer(int&,int&,int&);
es distinto a:
Código
  1. void leer(int,int,int);

Saludos.


Título: Re: FUNCIONES Y PROCEDIMIENTO
Publicado por: programador10 en 28 Abril 2011, 20:16 pm
TENIAS MUCHA RAZON. GRACIAS , UN ABRAZO A LA DISTANCIO. QUE CHEVERE COMPILO


Título: Re: FUNCIONES Y PROCEDIMIENTO
Publicado por: leogtz en 28 Abril 2011, 20:33 pm
De nada.