mercredi 2 septembre 2020

C++ If / Else If / Else Block - Always Falls Through to Else Block

Here a C/C++ snippet that is causing issues for me. For some reason, the code always drops into the 'else' block, even if the conditions in the 'if' or 'else if' blocks are true. If I replace the 'else' block with another 'else if' block-- the code in the previous 'if' or 'if else' block will run just fine (if the condition is true)! The code in the first two blocks will also run if I just delete the last block completely.

Can someone tell me what's going on here?

   if (text[i] == alphabet[j])
   {
       coded_text[i] = cipher[j];
   }
   else if (text[i] == (alphabet[j] - 32))
   {
       coded_text[i] = (cipher[j] - 32);
   }
   else
   {
       coded_text[i] = text[i];
   }

Aucun commentaire:

Enregistrer un commentaire