/**************************************************************************** * beer2.c * * Computer Science 50 * David J. Malan * * Sings "99 Bottles of Beer on the Wall." * * Demonstrates a while loop (and an opportunity for hierarchical * decomposition). ***************************************************************************/ #include #include int main(int argc, char * argv[]) { int n; /* ask user for number */ printf("How many bottles will there be? "); n = GetInt(); /* exit upon invalid input */ if (n < 1) { printf("Sorry, that makes no sense.\n"); return 1; } /* sing the annoying song */ printf("\n"); while (n > 0) { printf("%d bottle(s) of beer on the wall,\n", n); printf("%d bottle(s) of beer,\n", n); printf("Take one down, pass it around,\n"); printf("%d bottle(s) of beer on the wall.\n\n", n - 1); n--; } /* exit when song is over */ printf("Wow, that's annoying.\n"); return 0; }