r/shittyprogramming • u/Successful-Pay-4575 • Apr 20 '21
Thought I'd share my extensible fizzbuzz solution in C.
main(i,v) {
for (i=0;;i++,v=0) {
if (i % 3 == 0)
v+=1;
if (i % 5 == 0)
v+=2;
switch(v) {
case 0:
printf("%d\n", i);
break;
case 1:
printf("Fizz\n");
break;
case 2:
printf("Buzz\n");
break;
case 3:
printf("Fizzbuzz\n");
break;
}
}
And here it is extended for fizzbuzzbazz, a new game I just invented.
main(i,v) {
for (i=0;;i++,v=0) {
if (i % 3 == 0)
v+=1;
if (i % 5 == 0)
v+=2;
if (i % 7 == 0)
v+=4;
switch(v) {
case 0:
printf("%d\n", i);
break;
case 1:
printf("Fizz\n");
break;
case 2:
printf("Buzz\n");
break;
case 3:
printf("FizzBuzz\n");
break;
case 4:
printf("Bazz\n");
break;
case 5:
printf("FizzBazz\n");
break;
case 6:
printf("BuzzBazz\n");
break;
case 7:
printf("FizzBuzzBazz\n"):
break;
}
}
}
54
Upvotes
42
u/ekolis Apr 20 '21
"Extensible"? You don't even have one XML tag!
30
u/Glaiel-Gamer Apr 21 '21 edited Apr 21 '21
you can make it even more extensible with a few fairly simple changes
2
u/MisterQuacker Apr 21 '21
This:
for (i=0;;i++,v=0)Is it a thing in most languages where you can define multiple variables within a for loop????????? Like "i" and "v";
This whole time I've been declaring variables before my loop and then only defining the counter/incrementor "i" when instantiating the loop. I'm going to test in a few languages right after I click send for this post lol!