CHADS Posted April 29, 2007 Report Posted April 29, 2007 Hey guys Can you use a funCtion in a switch block instead of the normal pfintf("") #include <stdio.h> int main() { char letter; printf("press A or B or C..."); scanf("%c",letter); switch(letter) { case 'a' : option();break; //CAN THIS CASE TRIGGER A FUNCTION? case 'b' : option2();break; case 'c' : option3();break; defualt : printf("not a b or c"); } return main(); } WHERE WOULD I DECLARE A FUCTION IF I CAN CALL FROM THE SWITCH BLOCK CASE.? I was trying to create a multiple choice program where each individual answer would give way to different multiple choice questions for each origional question. i thought maybe that each answer would call a function that would call another switch block..... Quote
Buffy Posted April 30, 2007 Report Posted April 30, 2007 Your code should work fine (except for a few typos: "defualt" and "return main();"). You can put the function declarations right before the main block: void option() { ...code here... } void option2() { ...code here... } void option3() { ...code here... } int main() { ...your current code... } Happy hacking!Buffy Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.