/* CPP 230 - 9/17/2007 by: Joey Burgett Instructor: Mark Laffoon Project: Chapter 3; Number 5 Display 'bottles of beers' ditty. */ #include #include // Function prototype // @ Parameter 1 is the bottle of beer we're on. void display(int); using namespace std; int main(int argc, char *argv[]) { for (int cnt=100; cnt > 0; --cnt) { for (int cnt2=0; cnt2<2; cnt2++) { display(cnt); if (cnt2==0) { cout << " bottles of beer on the wall,\n"; } else { cout << " bottles of beer,\n"; } } cout << "Take one down, pass it around,\n"; display(cnt-1); cout << " bottles of beer on the wall.\n\n"; } system("PAUSE"); return EXIT_SUCCESS; } // Function to display english representations of numbers 1 thru 99. void display(int iBottle) { int iCount,iIndex; iCount=iBottle/10; iIndex=iBottle%10; switch (iCount) { case 2: cout << "Twenty"; break; case 3: cout << "Thirty"; break; case 4: cout << "Forty"; break; case 5: cout << "Fifty"; break; case 6: cout << "Sixty"; break; case 7: cout << "Seventy"; break; case 8: cout << "Eighty"; break; case 9: cout << "Ninety"; break; } // If bottle number is > 12, add a ' ' between words if ((iIndex > 0) && (iCount > 1)) cout << " "; if (iBottle<1) cout << "Zero"; // Numbers to Text Prodcedure switch (iIndex) { case 0: if (iBottle==10) cout << "Ten"; break; case 1: if (iBottle==11) { cout << "Eleven"; } else { cout << "One"; } break; case 2: if (iBottle==12) { cout << "Twelve"; } else { cout << "Two"; } break; case 3: // Special case for thirteen or twenty-three if (iBottle==13) { cout << "Thir"; } else { cout << "Three"; } break; case 4: cout << "Four"; break; case 5: // Special case for fifteen or twenty-five if (iBottle==15) { cout << "Fif"; } else { cout << "Five"; } break; case 6: cout << "Six"; break; case 7: cout << "Seven"; break; case 8: cout << "Eight"; break; case 9: cout << "Nine"; break; } // If bottle count is > 12 but less than 20, postfix 'teen' to number if ((iBottle>12) && (iBottle<20)) cout << "teen"; }