elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Usando Git para manipular el directorio de trabajo, el índice y commits (segunda parte)


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación C/C++ (Moderadores: Eternal Idol, Littlehorse, K-YreX)
| | |-+  Ayuda con este error en c++ undefined reference to `convertiratexto(float)'
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Ayuda con este error en c++ undefined reference to `convertiratexto(float)'  (Leído 3,145 veces)
andru23

Desconectado Desconectado

Mensajes: 2


Ver Perfil
Ayuda con este error en c++ undefined reference to `convertiratexto(float)'
« en: 6 Mayo 2015, 17:07 pm »

Buen Dia.

Me encuentro realizando un programa para calcular series, ingresando un numero por teclado, pero me aparece este error que no me deja continuar. el error es este (ccv9L5Du.o:NewFile.cpp:(.text+0x337): undefined reference to `convertiratexto(float)') Agradezco a quien me pueda ayudar comparto el codigo?
Código
  1. #include<iostream>
  2. #include<string>
  3. #include<cmath>
  4. #include<stdlib.h>
  5. #include<stdio.h>
  6.  
  7. using namespace std;
  8.  
  9.  
  10. string convertiratexto(float f);
  11.  
  12.  
  13.  
  14. int main() {
  15. float fact;
  16. float fact2;
  17. int i;
  18. float inv;
  19. float j;
  20. float k;
  21. float num1;
  22. float pot;
  23. float pot2;
  24. float suma;
  25. float sumatoria;
  26. string texto1;
  27. string texto2;
  28. string texto3;
  29. string texto4;
  30. string texto5;
  31. string texto6;
  32. string texto7;
  33. string texto8;
  34. string texto9;
  35. float total1;
  36. float total2;
  37. float total3;
  38. float total4;
  39. float total5;
  40. float total6;
  41. float total7;
  42. float total8;
  43. float total9;
  44. cout << "\nDigite un numero para calcular serie" << endl;
  45. cin >> num1;
  46. texto1 = "";
  47. texto2 = "";
  48. texto3 = "";
  49. texto4 = "";
  50. texto5 = "";
  51. texto6 = "";
  52. texto8 = "";
  53. texto7 = "";
  54. total1 = 0;
  55. total2 = 0;
  56. total3 = 0;
  57. total4 = 0;
  58. total5 = 0;
  59. total6 = 0;
  60. total7 = 0;
  61. total8 = 0;
  62. sumatoria = 0;
  63. inv = num1;
  64. for (i=1;i<=num1;i++) {
  65. fact = 1;
  66. suma = 0;
  67. pot = 0;
  68. if (i==num1) {
  69. texto1 = texto1+(convertiratexto(i)+"^2");
  70. texto2 = texto2+(convertiratexto(i)+"!");
  71. texto3 = texto3+((convertiratexto(i)+"^")+convertiratexto(i));
  72. texto6 = texto6+convertiratexto(i);
  73. texto9 = texto9+((convertiratexto(i)+"^")+convertiratexto(inv));
  74. } else {
  75. texto1 = texto1+(convertiratexto(i)+"^2 +");
  76. texto2 = texto2+(convertiratexto(i)+"! +");
  77. texto3 = texto3+(convertiratexto(i)+"^"+convertiratexto(i)+" +");
  78. texto6 = texto6+(convertiratexto(i)+" +");
  79. texto9 = texto9+(convertiratexto(i)+"^"+convertiratexto(inv)+" +");
  80. }
  81. if (i%2==0 ){
  82. texto4 = texto4+(" +"+convertiratexto(i)+"^"+convertiratexto(i));
  83. } else {
  84. texto4 = texto4+(" -"+convertiratexto(i)+"^"+convertiratexto(i));
  85. }
  86. texto5 = texto5+("("+convertiratexto(i)+"+(");
  87. texto7 = texto7+"(";
  88. texto8 = texto8+"(";
  89. for (j=1;j<=i;j++) {
  90. fact2 = 1;
  91. for (k=1;k<=j;k++) {
  92. fact2 = (fact2*k);
  93. }
  94. fact = (fact*j);
  95. suma = (suma+j);
  96. pot = pot+(pow(i,j));
  97. pot2 = pot+(pow(i,fact2));
  98. fact2 = 0;
  99. if (j==i) {
  100. if (i==num1) {
  101. texto7 = texto7+convertiratexto(i)+"^"+convertiratexto(j)+") ";
  102. texto8 = texto8+convertiratexto(i)+"^!"+convertiratexto(j)+") ";
  103. } else {
  104. texto7 = texto7+convertiratexto(i)+"^"+convertiratexto(j)+") + ";
  105. texto8 = texto8+convertiratexto(i)+"^!"+convertiratexto(j)+") + ";
  106. }
  107. texto5 = texto5+convertiratexto(j)+")) + ";
  108. } else {
  109. texto7 = texto7+convertiratexto(i)+"^"+convertiratexto(j)+"+";
  110. texto8 = texto8+convertiratexto(i)+"^!"+convertiratexto(j)+" +";
  111. texto5 = texto5+convertiratexto(j)+"+";
  112. }
  113. }
  114. total1 = total1+(i*i);
  115. total2 = total2+fact;
  116. total3 = total3+(pow(i,i));
  117. total5 = total5+(i+suma);
  118. total7 = total7+pot;
  119. total8 = total8+pot2;
  120. total9 = total9+(pow(i,inv));
  121. if (i%2==0) {
  122. total4 = total4+(pow(i,i));
  123. } else {
  124. total4 = total4-(pow(i,i));
  125. }
  126. sumatoria = sumatoria+i;
  127. inv = (inv-1);
  128. }
  129. total6 = total2/sumatoria;
  130. cout << "\nSERIE NUMERO 1" << endl;
  131. cout << texto1 << " =" << total1 << endl;
  132. cout << " " << endl;
  133. cout << "\nSERIE NUMERO 2" << endl;
  134. cout << texto2 << " =" << total2 << endl;
  135. cout << " " << endl;
  136. cout << "\nSERIE NUMERO 3" << endl;
  137. cout << texto3 << " =" << total3 << endl;
  138. cout << " " << endl;
  139. cout << "\nSerie NUMERO 4" << endl;
  140. cout << texto4 << " =" << total4 << endl;
  141. cout << " " << endl;
  142. cout << "\nSerie NUMERO 5" << endl;
  143. cout << texto5 << " =" << total5 << endl;
  144. cout << " " << endl;
  145. cout << "\nSERIE NUMERO 6" << endl;
  146. cout << "( " << texto2 << " )/(" << texto6 << " ) =" << total6 << endl;
  147. cout << " " << endl;
  148. cout << "\nSERIE NUMERO 7" << endl;
  149. cout << texto7 << " =" << total7 << endl;
  150. cout << " " << endl;
  151. cout << "\nSERIE NUMERO 8" << endl;
  152. cout << texto8 << " =" << total8 << endl;
  153. cout << " " << endl;
  154. cout << "\nSERIE NUMERO 9" << endl;
  155. cout << texto9 << " =" << total9 << endl;
  156.  
  157.  
  158. return 0;
  159. }
  160.  
  161.  
  162.  


« Última modificación: 6 Mayo 2015, 17:08 pm por andru23 » En línea

‭‭‭‭jackl007


Desconectado Desconectado

Mensajes: 1.403


[UserRPL]


Ver Perfil WWW
Re: Ayuda con este error en c++ undefined reference to `convertiratexto(float)'
« Respuesta #1 en: 6 Mayo 2015, 17:41 pm »

Hola, en el código defines la función: string convertiratexto(float f);

Pero, en ninguna parte del código, está definido el código de la función.


Deberías agregar algo como:


string convertiratexto(float f){
  // ...codigo

  return "";
}

quizás te convenga implementar esta forma de hacer la conversión de float -> string:

Código:
#include <string>
#include <sstream>

namespace patch
{
    template < typename T > std::string to_string( const T& n )
    {
        std::ostringstream stm ;
        stm << n ;
        return stm.str() ;
    }
}

#include <iostream>

int main()
{
    std::cout << patch::to_string(1234) << '\n' << patch::to_string(1234.56) << '\n' ;
}


« Última modificación: 6 Mayo 2015, 17:48 pm por ‭‭‭‭jackl007 » En línea

Josuex24

Desconectado Desconectado

Mensajes: 4


Ver Perfil
Re: Ayuda con este error en c++ undefined reference to `convertiratexto(float)'
« Respuesta #2 en: 10 Mayo 2015, 17:54 pm »

Amigo creo que el error es que en el int main estas haciendo llamados a la función convertiratexto y en ningún lado has codificado esta función, pienso yo, me dio flojera leer todo el int main xd, deberías trabajar de manera mas modular así es mas fácil al momento de corregir errores.
En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines