title: How does 'double' to 'unsigned char' casting work?
body: <p>I want to be able to cast double into an 'unsigned char' and I don't seem to get why the 'unsigned char' result came in character '&gt;' even when casting is done (inside the function). Can anyone explain to me where the issue lies and how to fix it? That would be a great help.</p>
  <pre><code> #include &lt;iostream&gt;
   using namespace std;
  
   unsigned char f_wd(double force1);
  
   int main() {
   double x = 512;
  
    int dog = f_wd(x);
    cout &lt;&lt; dog &lt;&lt; endl;            // this outputs 62 
  
    unsigned char cat = f_wd(x);
    cout &lt;&lt; cat &lt;&lt; endl;             // but this outputs '&gt;'
  
  }
  
  
   unsigned char f_wd(double force1){
   double animal = (124.0/1024)*force1;
  unsigned char animal2 = (unsigned char)animal;
   return animal2;
  
   }
  </code></pre>