title: Printing result of Caesar cipher program
body: <p>I'm trying to add <code>"Encrypted message: "</code> before the encrypted message is printed.</p>
  
  <p>When I put the <code>printf</code> statement inside the "while" loop, I get something along the lines of:
  <code>AEncrypred message: BEncrypted message: CEncrypted message:</code> etc.</p>
  
  <p>If I try and put the <code>printf</code> statement outside the loop, nothing prints.</p>
  
  <p>Is there a way to print <code>"Encrypted message: "</code> before the result while still using <code>putchar();</code> ?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;ctype.h&gt;   
  
  char encrypt(char in, int key) 
  {
      if (isalpha(in)) 
      {  
          if (isupper(in)) 
          {
              return (((in-'A') + key) % 26) + 'A';
          }
          else 
          {
              return (((in-'a') + key) % 26) + 'a';
          }
      }
      else return in;
  }
  
  int main()
  {
      int key;
      char ch, res;
  
      printf("Enter shift amount (1-25):\n");
      scanf("%d", &amp;key);
  
      printf("Enter message to be encrypted:\n");
      getchar();
  
      while (ch != '\n') 
      {
          ch = getchar();
          res = encrypt(ch, key);
          putchar(res);
      }
      return 0;
  }
  </code></pre>