Is there any subjects I miss learning before starting on a Hangman game?
The subjects i have a pretty good grasp of is:
Variables,
input and output,
loops,
arrays,
vectors,
switch statement,
(if, else if, else) statements,
structures,
enumerators,
constructures & deconstructures,
dynamic memory allocation,
try & catch,
functions,
pointers,
How are you supposed to know which word was chosen by the random number generator?
Through a switch statement?
Let's say I had 3 words that could be called into the Hangman game.
Do I have to make a function for each word scenario in the switch statement?
Isn't there an easier way than doing something like this?:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
main(){
char words[15][3] = {"Word0", "Word1", "Word2"}; // Example of the words that could be in the Hangman game to guess.
srand(time(0));
int rand_numb = rand()%3;
switch(rand_numb){
case 0:
Word0_Scenario(); // Function call if word0 was chosen.
break;
case 1:
Word1_Scenario(); // Function call if word1 was chosen.
break;
case 2:
Word2_Scenario(); // Function call if word2 was chosen.
}
}
|
I know that 3 words isn't much to do a function for each scenario. But let's say I had 30 words instead? Do I really have to make a function for each scenario that is chosen? Isn't there an easier way to do it? This method will most likely make me have to copy/paste code in each function, that almost looks identical anyways.