The Enchanted Cave 2
Delve into a strange cave with a seemingly endless supply of treasure, strategically choos
4.34 / 5.00 31,296 ViewsGhostbusters B.I.P.
COMPLETE edition of the interactive "choose next panel" comic
4.07 / 5.00 10,082 ViewsIn C i've been having a lot of trouble making while switch loops. Can anyone help?
Ok let's do a simple breakdown of the while loop....
In C, in an expression, any number other then 0 is considered true. For example...
while(Value)
{
printf("I'm True if Value is not equal to one and I keep looping!");
}
or you can do it the other way
while(!Value)
{
printf("I'm true if value is equal to zero because the ! means not in C!");
}
Now the good ol' switch case.....
the basic template is this
switch ( expression )
{
case value_1 : statement
............................................
default : statement
}
The expression can be anything that gives (or returns which means you can even put a function in here!) an integer value; such as a long, int, double, or a char. Let me give an example..
(Note I didn't want to make a great UI at all)
int menu_choice=0;
printf("1 for this, 2 for that, 3 for what?");
scanf( "%d", &menu_choice);
switch(menu_choice)
{
case 1: printf("This!");
case 2: printf("That!");
case 3: printf("What?");
default: printf("Wrong value!!!");
}
My C might be a little broken, haven't used it in awhile.... but hopefully that clears it up for you.