After some reconsideration of your question this morning (whether to
use a switch or not) and now seeing what you re trying to do, I think
my original response was a bit short-sighted.

I don't know what your skill level is in C programming, but you are
going to have to implement some kind of data abstraction and use both
structures and functions to operate on those structures, since you are
creating generic characters and then giving them specific capabilities
based on the more specific types. That right there is just begging for
an object-oriented solution... and if you go that route, then you
should learn C++.

At the very least, though, a switch statement may ultimately be clumsy
solution, at best (and if/else no better). If you know how to use
function pointers, it might be better to implement a callback table
(an array of function pointers) that is indexed by the character or
letter of the user's input. This is a basic menu design also, and can
be extended (again, going with a object-oriented solution in C++ is
even better)


On 10/1/07, secretosamani <[EMAIL PROTECTED]> wrote:
> Can anyone tell me what's wrong here? The code will run but it won't
> read the switch case statement in my first switch case statement.
>
> /* This code will guide you through your own adventure where you can
> choose to be a gangster, a knight, or Chuck Norris.
>
> The ALGORITHM for the ENTIRE code is:
> Welcome Message
> ask/get answer from 3 options to choose from
> switch answer
>     case 'g'
>          print hello (gangster)
>     case 'k'
>          print hello (knight)
>     case 'c'
>          print hello (Chuck Norris)
>     default
>         error
> */
>
> #include <stdio.h>
> #include <stdlib.h>
>
> int main(void)
> {
>     //declare variable
>     char menu = 'g' || 'k' || 'c';
>     char gmenu = 'a' || 'b';
>
>         //Welcome Message
>         printf("Welcome to choose your own adventure.\n\n"
>         "You can choose between an adventure as a gangster, a knight,
> or "
>         "Chuck Norris.\n\n"
>         "Please enter \"g\" for Gangster, \"k\" for Knight, and \"c\"
> for "
>         "Chuck Norris.\n"
>         "Choose from one of the following: \n"
>                     "1.\tGangster\n"
>                     "2.\tKnight\n"
>                     "3.\tChuck Norris\n\n");
>             scanf("%c",&menu);
>
>             //switch depending on answer
>             switch (menu)
>             {
>                 case 'g':
>                     printf("You are a hardcore ganster from the
> streets "
>                     "of Compton. You just got out of jailand you
> came "
>                     "back to your hood only to find out that it had
> been "
>                     "taken over by arival gang.\n"
>                     "Would you rather\n"
>                     "a: Join the rival gang\n"
>                     "or\n"
>                     "b: Get some guys together to take your hood
> back\n");
>                     break;
>
>                           scanf("%c", &gmenu);
>                           switch (gmenu)
>                           {
>                                  case 'a':
>                                       printf("You've selected a.\n");
>                                       break;
>                                  case 'b':
>                                       printf("You've selected b.\n");
>                                       break;
>                           }
>
>                 case 'k':
>                     printf("You are a holy knight who just passed
> training."
>                     " Now you need to get some quests under your belt
> if "
>                     "you want to be respected as a knight. You go
> into town"
>                     " to\n"
>                     "find some quests and you encounter two people.\n"
>                     "Would you rather\n"
>                     "a: Go deep into a mine to find hidden treasure\n"
>                     "or\n"
>                     "b: Rescue a beautiful maiden\n");
>                     break;
>
>                 case 'c':
>                     printf("You are Chuck Norris. Men worship you and
> women "
>                     "can't resist you.\n"
>                     "You are considered by all as a God.\n"
>                     "The game is over. You win!\n\n");
>                     break;
>                 //Error
>                 default :
>                     printf("Error, that option is not valid.\n\n");
>                     break;
>            }
>
>     system("pause");
>     return(0);
> }
>
>
>
>
> To unsubscribe, send a blank message to <mailto:[EMAIL PROTECTED]>.
> Yahoo! Groups Links
>
>
>
>


-- 
------------------------------------------------------------
"In the rhythm of music a secret is hidden;
    If I were to divulge it, it would overturn the world."
               -- Jelaleddin Rumi

Reply via email to