You appear to be confused about a number of things, most related to program flow and programming logic:
1. You intialize a number of
char
variables and never change them, but then, later, you test their value. Apparently what you intended to do is compare the user input against the values you stored in these variables? Judging by the rest of the program, these variables aren't needed at all, or should be defined as constant and used as the value to compare the input against. (but see point 3 below)
2. You initialize num once, and then never change it. Apparently your intention is to recalculate it every time the user requests a new card, i. e. you need to call the random number function within the main loop.
3. You repeatedly print out instructions to the user, requesting input, but you never read that input! You didn't even define a variable to hold that input.
I suggest you rewrite that program as follows:
const char begin_game = 'b';
const char end_game = 'e';
const char instructions = 'i';
const char credits = 'c';
const char deal_a_card = 'd'; const char stay_hand = 's';
void print_intro() {
}
void print_instructions() {
}
void print_credits() {
}
void deal() {
}
void stay() {
}
bool process_input(char choice) {
bool continue = true; if (choice == end_game) {
continue = false;
}
else {
switch (choice) { case begin_game:
break;
case credits:
print_credits();
break;
default:
}
}
return continue;
}
int main() {
int card=0; char choice=' ';
intro();
do { print_instructions(); choice = getc(); while (process_input(choice));
return 0;
}
I deliberately introduced a whole lot of functions for trivial tasks - on purpose! It will make the main loop much shorter, and you will have an easier time to later add more commands or change existing ones, without losing a lot of time digging through your code. This will also be helpful when you go for more complex games.
The main game loop is pretty simple:
1. present the user with some choices
2. get the user input
3. process the input
Repeat until processing returns false