Program that converts a number to a letter of the alphabet - follow-up This is a follow up from my previous post: Program that converts a number to a letter of the alphabet

This is meant to teach my little brother (who only knows how to make games in Geometry Dash) about C, and computers. This is an example I've written meant to be shown and explained to him.

#include &lt;stdio.h&gt;
#include &lt;stdbool.h&gt;

int main() {
  //A string is an array of characters
  const char * alphabet = "ABCDEFGHIJKLMNOPQRSTUVWSYZ";
  int temp,    letter   = 0;

  while( (1 &lt;= letter &amp;&amp; letter &lt;= 26) == false){
    /* 
     * if scanf fails, valadate input to avoid infinite loop 
     * (the below while statement). 
     * Uncomment the below printf and comment out the below 
     * while statement to see what happens if you type 
     * something like "asdef4grvgrthd" instead of a number.
     */
    if(scanf("%d", &amp;letter) != 1){
      while((temp=getchar()) != EOF &amp;&amp; temp != '\n');
      //printf("Fun loop :) ");
    }
  }

  printf("The number %i corresponds to the letter '%c'\n", 
          letter, alphabet[letter-1]);
}


This is intended to help beginners understand C by being a slightly harder "Hello World" program.
int letter is not a letter. When printing you call it The number. Name it accordingly: int number.
The condition (1 &lt;= letter &amp;&amp; letter &lt;= 26) == false is very hard to follow. As a general rule, avoid boolean constants in conditions. Rewriting it as:

!(1 &lt;= letter &amp;&amp; letter &lt;= 26)


immediately calls for a deMorgan transformation into a much more readable form:

(letter &lt; 1 || letter &gt; 26)


It is also recommended to not rely on the operator precedence, which is very easy to get wrong. Use parenthesis instead:

((letter &lt; 1) || (letter &gt; 26))

Avoid raw loops. Each loop represent an important algorithm, and as such deserves a name. The goal of:

while((temp=getchar()) != EOF &amp;&amp; temp != '\n');


is to discard the line. Factor it out into a function:

void discard_line()
{
    int temp;
    while((temp=getchar()) != EOF &amp;&amp; temp != '\n') {
    }
}


As a perk benefit, temp is no longer cluttering the essential logic.

I also recommend to be a bit more explicit with the empty loops.
Avoid magic numbers. 26 is really strlen(alphabet). Better yet, declare the alphabet as an array, rather than a pointer, and use sizeof.