Execute HQ9+: Difference between revisions

Content added Content deleted
No edit summary
No edit summary
Line 26: Line 26:
printf("Take one down, pass it around\n");
printf("Take one down, pass it around\n");
printf("%d bottles of beer on the wall\n\n", --bottles);
printf("%d bottles of beer on the wall\n\n", --bottles);
} while( bottles > 0 );
break;

case '+':
//Am I the only one finding this one weird? :o
accumulator++;
break;
}
}
};</lang>

=={{header|C++}}==
Basically the same as the C example, although this has been C++'ified with strings and streams.
<lang cpp>void runCode(string code)
{
int c_len = code.length();
int accumulator, bottles;
for(int i=0;i<c_len;i++)
{
switch(code[i])
{
case 'Q':
cout << code << endl;
break;

case 'H':
cout << "Hello, world!" << endl;
break;

case '9':
//Nice bottles song alg. from RC :)
bottles = 99;
do {
cout << bottles << " bottles of beer on the wall" << endl;
cout << bottles << " bottles of beer" << endl;
cout << "Take one down, pass it around" << endl;
cout << --bottles << " bottles of beer on the wall" << endl << endl;
} while( bottles > 0 );
} while( bottles > 0 );
break;
break;