Start here:
/* Purpose: irritation Input: none Output: I know a song that gets on everybody's nerves, everybody's nerves, everybody's nerves! I know a song that gets on everybody's nerves, and this is how it goes: endlessly Test: I know a song that gets on everybody's nerves, everybody's nerves, everybody's nerves! I know a song that gets on everybody's nerves, and this is how it goes: I know a song that gets on everybody's nerves, everybody's nerves, everybody's nerves! I know a song that gets on everybody's nerves, and this is how it goes: ... */ #include <iostream> #include <string> using namespace std; int main() { while (true) { cout << "I know a song that gets on everybody's nerves," << endl; cout << "everybody's nerves, everybody's nerves!" << endl << endl; cout << "I know a song that gets on everybody's nerves," << endl; cout << "and this is how it goes:" << endl << endl; } system("pause"); return 0; }
Here is an intermediate version:
/* Purpose: A distracting song for Children Input : none Output : 99 bottles of milk on the wall, 99 bottles of milk on the wall, take one down and pass it around, 98 bottles of milk on the wall. 98 bottles of milk on the wall, 98 bottles of milk on the wall, take one down and pass it around, 97 bottles of milk on the wall. ... 2 bottles of milk on the wall, 2 bottles of milk on the wall, take one down and pass it around, 1 bottle of milk on the wall. 1 bottle of milk on the wall, 1 bottle of milk on the wall, take one down and pass it around, no bottles of milk on the wall. Traditionally starting at 99 Test : Using a variable "verses" adjust how many verses are to be sung: At verses = 99 you get the output given above. At verses = 4 you get: 4 bottles of milk on the wall, 4 bottles of milk on the wall, take one down and pass it around, 3 bottles of milk on the wall. 3 bottles of milk on the wall, 3 bottles of milk on the wall, take one down and pass it around, 2 bottles of milk on the wall. 2 bottles of milk on the wall, 2 bottles of milk on the wall, take one down and pass it around, 1 bottle of milk on the wall. 1 bottle of milk on the wall, 1 bottle of milk on the wall, take one down and pass it around, no bottles of milk on the wall. */ #include <iostream> #include <string> using namespace std; int main() { const int verses = 5; for (int i = verses; i > 0; i--) { if (i == 1) { cout << i << " bottle of milk on the wall," << endl; cout << i << " bottle of milk on the wall," << endl; } else { cout << i << " bottles of milk on the wall," << endl; cout << i << " bottles of milk on the wall," << endl; } cout << "take one down and pass it around," << endl; int remainingBottles = i - 1; if (remainingBottles == 1) { cout << "1 bottle of milk on the wall." << endl << endl; } else if (remainingBottles == 0) { cout << "no bottles of milk on the wall." << endl << endl; } else { cout << remainingBottles << " bottles of milk on the wall." << endl << endl; } } system("pause"); return 0; }
Here is a menu example
#include <iostream> #include <string> using namespace std; string bottleness(int j) { string bottleword; if (j == 1) { bottleword = " bottle"; } else { bottleword = " bottles"; } return bottleword; } void getusercommand(string & answer) { cout << "\"Q\" -- quit\n"; cout << "\"S\" -- sing\n"; cout << "\"X\" -- say something nice\n"; cout << "what do you want me to do? "; getline(cin,answer); } void sing() { int verses = 5 ; for (int i = verses; i > 0 ; i--) { cout << i << bottleness(i) << " of milk on the wall\n"; cout << i << bottleness(i) << " of milk.\n"; cout << "you take one down and pass it around,\n"; cout << i-1 << bottleness(i-1) << " of milk on the wall.\n\n"; } } int main () { string ans="Q"; getusercommand(ans); while((ans != "Q") && (ans != "q")) { if ((ans == "S") || (ans == "s")) { sing(); } else if ((ans == "X") || (ans == "x")) { cout << "Something nice.\n"; } else { cout << "invalid input, try again.\n"; } getusercommand(ans); } system("pause"); return 0; }Back to top