Update c/beer-song verse
This commit is contained in:
+27
-23
@@ -1,36 +1,40 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
void verse(char* response, int bottles) {
|
int verse(char* response, int bottles) {
|
||||||
if (bottles < 0) {
|
if (bottles < 0) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (bottles) {
|
switch (bottles) {
|
||||||
case 0:
|
case 0:
|
||||||
sprintf(response,
|
return sprintf(response,
|
||||||
"No more bottles of beer on the wall, no more bottles of beer.\n"
|
"No more bottles of beer on the wall, "
|
||||||
"Go to the store and buy some more, "
|
"no more bottles of beer.\n"
|
||||||
"99 bottles of beer on the wall.\n");
|
"Go to the store and buy some more, "
|
||||||
return;
|
"99 bottles of beer on the wall.\n");
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
sprintf(response,
|
return sprintf(response,
|
||||||
"1 bottle of beer on the wall, 1 bottle of beer.\n"
|
"1 bottle of beer on the wall, "
|
||||||
"Take it down and pass it around, "
|
"1 bottle of beer.\n"
|
||||||
"no more bottles of beer on the wall.\n");
|
"Take it down and pass it around, "
|
||||||
return;
|
"no more bottles of beer on the wall.\n");
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
sprintf(response,
|
return sprintf(response,
|
||||||
"2 bottles of beer on the wall, 2 bottles of beer.\n"
|
"2 bottles of beer on the wall, "
|
||||||
"Take one down and pass it around, "
|
"2 bottles of beer.\n"
|
||||||
"1 bottle of beer on the wall.\n");
|
"Take one down and pass it around, "
|
||||||
return;
|
"1 bottle of beer on the wall.\n");
|
||||||
|
|
||||||
default:
|
default:
|
||||||
sprintf(response,
|
return sprintf(response,
|
||||||
"%d bottles of beer on the wall, %d bottles of beer.\n"
|
"%d bottles of beer on the wall, "
|
||||||
"Take one down and pass it around, "
|
"%d bottles of beer.\n"
|
||||||
"%d bottles of beer on the wall.\n",
|
"Take one down and pass it around, "
|
||||||
bottles, bottles, bottles - 1);
|
"%d bottles of beer on the wall.\n",
|
||||||
return ;
|
bottles, bottles, bottles - 1);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user