EvilZone
Programming and Scripting => C - C++ => : Polyphony October 25, 2012, 04:02:44 AM
-
His little challenge was to write a program that will print out a deck of cards, but I'm having some trouble with what seems to be a little fluke in the code or something.
This is main.c
http://pastebin.com/dnFaHccJ
and this is main.h
http://pastebin.com/pnBJKgS9
When you compile and run it with "gcc -std=gnu99 -Wall main.c main.h -o main" it prints all the things I meant for it to print
Ace of clubs
2 of clubs
3 of clubs
etc... etc..
but it does diamonds like 3 times at the end of the run, does anybody know why? I'll continue messing with it trying to get it fixed, but one of you guys might see some obvious noob thing I messed up on.
oooh! I can't believe I forgot about the break statement. I had forgotten alot about switch() case: statements so I googled a little and I guess forgot about breaking lol.
-
"break;"
switch (variable) {
case 0:
do_something();
break; /* do this so it doesn't automatically fall through & execute the others */
case 1:
do_something();
case 2: /* allow fall-through to execute multiple statements */
something_else();
break; /* break this execution path which could include do_something() from case #1 */
default:
printf("wtf?\n");
}