[Solved] How to return “” OR empty when value of float is 1


You have marked this as C++

(4-1i) should be shown as (4-i)

You might find std::stringstream helpful. It simplifies the special handling for the imaginary part:

virtual int foo()
{
   std::cout << std::endl;
   show(4, -2);
   show(5, -1);

   return(0);
}

void show(int real, int imaginary)
{
   std::stringstream ss; // default is blank
   if      (-1 == imaginary)   { ss << "-i)"; }
   else /* (-1 != imaginary)*/ { ss << imaginary << "i)"; }

   std::cout << "("
             << std::noshowpos << real
             << std::showpos   << ss.str()
             << std::endl;
}

with output

(4-2i) 
(5-i)

3

solved How to return “” OR empty when value of float is 1