c++ - Check Writer Function challenge -


saluton mundo, i've been working on function prints lettering on check based upon numbers. problem made void, , have no clue how convert void-> string. impossible if ask me. in short, how can rewrite returns string.

my code below:

void numalet(string &can) {     int connum= atoi(can.c_str());     float connumf= atof(can.c_str());      //snippet find cents.     float cen= (int)((connumf- connum)* 100);      string basic[20]= { " ", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten",                         "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"},             diez[9]= { "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"};      if(connum< 20)         cout<< basic[connum]<< " , "<< (cen+ 1) << " cents.";     else if(connum< 100 && connum> 19)     {         int num= connum% 100;         if(num% 10!= 0)             cout<< diez[num/10- 1]<< " "<< basic[num% 10]<< " , "<< (cen+ 1) << " cents.";         else             cout<< diez[connum/ 10- 1]<< " , "<< (cen+ 1)<< " cents.";     }     else if(connum> 99 && connum< 1000)     {         int num1= connum% 1000;         cout<< basic[num1/ 100]<< " "<< "hundred ";         int num2= connum% 100;          if(connum< 20)             cout<< basic[num2]<< " , "<< (cen+ 1) << " cents.";         else if(num2< 100 && num2> 19)         {             if(num2% 10!= 0)                 cout<< diez[num2/ 10- 1]<< " "<< basic[num2% 10]<< " , "<< (cen+ 1) << " cents.";             else                 cout<< diez[num2/ 10- 1]<< " , "<< (cen+ 1) << " cents.";         }     }     else if(connum> 999 && connum< 10000)     {         cout<< basic[connum/ 1000]<< " "<< "thousand ";         int num1= connum% 1000;         cout<< basic[num1/ 100]<< " "<< "hundred ";         int num2= connum% 100;          if(connum< 20)             cout<< basic[num2]<< " , "<< cen << " cents.";         else if(num2< 100 && num2> 19)         {             if(num2% 10!= 0)                 cout<< diez[num2/ 10- 1]<< " "<< basic[num2% 10]<< " , "<< (cen) << " cents.";             else                 cout<< diez[num2/ 10- 1];         }     } } 

output:

nine thousand 9 hundred ninety 9 , 99 cents.

p.s: out of blue returns 99, 100 when cen called, why added + 1.

thank help.

firstly, include lib:

#include <sstream> 

then, instantiate std::stringstream:

std::stringstream ss; 

replace cout<< ss<<.

finally, return string stream string.

return ss.str(); 

Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -