/* This program is a fun demonstration of the for loop. */

#include <stdio.h> /* you need this to get anything running in C */
#include <stdlib.h> /* need this for the system("PAUSE"); */
#include <conio.h> /* for the getch(); function performing
                           keyboard input and output */ 
#include <ctype.h> /* for the toupper(); character conversion function */

int main()
{
    int x = 100; /* Naturally, we start with 100 bottles of beer. */
    char c;
    
    while (x != 0)
    {
          --x;      /* decrement the counter */
		    /* Now x is one less than
		       the previous initialization. */
          
          printf("%d bottles of beer on the wall!\n", x);
          printf("%d bottles of BEER!!\n", x);
          printf("Take one down, pass it around --\n");
          printf("%d bottles of beer on the wall!!\n", x);
          
          printf("Do you want another beer?\n");
          printf("\n\nPress Y for another, N to stop the madness:\n");
          
          c = toupper(getch()); /* get key */
				/* This is where both conio.h and
				   ctype.h come in to play */
          
          if (c == 'Y')
          {
                putchar(c);
                printf("\n");      /* display char */
                continue;          /* another beer coming up! */
                }
                
                if (c == 'N')
                {
                      printf("No more beer for you!!\n");

                      break;          /* stops the madness */
                      }
                      
                      if ( x = 1)

			/* If you've stuck with it this long,
			   you deserve one. */

                      {
                           printf("Time to buy more beer!!\n");
                           }
         }
          
  system("PAUSE");	
  return 0;
}


:: Top ::

code dog Tucker
E2 logo
End Poverty
Debt AIDS Trade Africa
World Community Grid
Valid XHTML 1.0 Transitional