Test Foro de elhacker.net SMF 2.1

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 (cpp) [Seleccionar]
#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;
}


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 (cpp) [Seleccionar]
#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: 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 (cpp) [Seleccionar]
void leer(int&,int&,int&);
void operacion(int &,int &,int &);


Código (cpp) [Seleccionar]

#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: 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 (cpp) [Seleccionar]
void leer(int,int,int);
void operacion(int ,int ,int );


Y debe ser así:

Código (cpp) [Seleccionar]
void leer(int&,int&,int&);
void operacion(int &,int &,int &);


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

Código (cpp) [Seleccionar]
void leer(int&,int&,int&);
es distinto a:
Código (cpp) [Seleccionar]
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.