/**************************************************************************** * beer4.c * * Computer Science 50 * David J. Malan * * Sings "99 Bottles of Beer on the Wall." * * Demonstrates hierarchical decomposition and parameter passing. ***************************************************************************/ #include #include // function prototype void chorus(int); 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) chorus(n--); // exit when song is over printf("Wow, that's annoying.\n"); return 0; } /* * void * chorus(int b) * * Sings about specified number of bottles. */ void chorus(int b) { string s1, s2; // use proper grammar s1 = (b == 1) ? "bottle" : "bottles"; s2 = (b == 2) ? "bottle" : "bottles"; // sing verses printf("%d %s of beer on the wall,\n", b, s1); printf("%d %s of beer,\n", b, s1); printf("Take one down, pass it around,\n"); printf("%d %s of beer on the wall.\n\n", b - 1, s2); }