/**************************************************************************** * beer-2.c * * David J. Malan * malan@harvard.edu * * Sings "99 Bottles of Beer on the Wall." * * Demonstrates a condition within a for loop. ***************************************************************************/ #include #include int main(void) { // ask user for number printf("How many bottles will there be? "); int n = GetInt(); // exit upon invalid input if (n < 1) { printf("Sorry, that makes no sense.\n"); return 1; } // sing the annoying song printf("\n"); for (int i = n; i > 0; i--) { string s = (i == 1) ? "bottle" : "bottles"; string t = (i == 2) ? "bottle" : "bottles"; // sing verses printf("%i %s of beer on the wall,\n", i, s); printf("%i %s of beer,\n", i, s); printf("Take one down, pass it around,\n"); printf("%i %s of beer on the wall.\n\n", i - 1, t); } }