Исправлена ваша проблема.Добавлены комментарии, поясняющие.Надеюсь, я все поймал.Протестировал программу, и теперь она работает нормально.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
#include <string.h>
//#include <unistd.h>
#define MAX_QUESTION 1000
#define STATEMENT_AMOUNT 10
int random_num_generator();
void statement_picker(int x);
int main(void) {
char temp;
int rand;
// Your while condition really just needs to be scanning 1 character.
// No point in scanning the entire string, because we don't even use the string
// The scanning jus tells us when to start the loop again
while (1) {
// The introduction of our program
system("cls");
printf("MAGIC 8 BALL!\n");
printf("Press Enter When Ready.\n");
getch();
// Asking user to enter in their question
system("cls");
printf("What is your question?\n");
printf("Only enter yes or no questions!\n");
// You have to flush (aka clear) stdin. Because it uses your previous inputs
// automatically. For example, if you type "I am the best?". The program will not work
// properly for num_of_words - 1 iterations. So 4 - 1. Will not work properly for
// 3 iterations
// Also you don't need to scan in the word, because we don't really care what question
// the user typed. You can save some memory by only scanning in a single character.
// We only use scanf to give a real magic 8 ball experience by stopping and waiting
// for the user to type their question.
scanf("%c", &temp);
fflush(stdin);
// Generating a random number
printf("The answer you seek: ");
rand = random_num_generator();
statement_picker(rand);
// So I noticed here you cls, but you cls without waiting. This the user won't
// be able to read your answer in time. So you should cls after you ask the user
// to quit, or have a timer. Commented a timber for you below. You also need to
// include the unistd.h library to use the sleep function. Just uncomment it
// in the #includes section if you want the timer.
// sleep(10);
// system("cls");
// Asking the user if they want to try again
printf("Would you like to ask another question?\n");
printf("Press [x] to quit\n");
printf("Press any other character to continue\n");
scanf("%c", &temp);
if (temp == 'x') break;
// Flush at the end too, just in case the person types multiple things rather than
// one characters
fflush(stdin);
}
system("cls");
return 0;
}
// Generates a random number between 0 - 10.
/* I noticed in your switch statement you start at case 1. You should start at case 0,
* because you are using the modulus operator Just for example, if rand generators 30 and
* you have 10 cases you will be doing (30 % 10) which is equal to 0 because 10 goes into 10,
* 3 times with no remainders If you really want to start your switch case at 1,
* then you have to plus one to the return value in random_num_generator
*/
int random_num_generator() {
time_t t;
srand((unsigned) time(&t));
return rand() % STATEMENT_AMOUNT;
}
// Picks a statement and prints it, depending on the value of x
void statement_picker(int x){
switch(x){
// Your case should start at 0, not 1 because you will never print out case 0
// the way you had it before.
case 0 : printf("YES!\n");break;
case 1 : printf("NO!\n");break;
case 2 : printf("It's a thumbs down.\n");break;
case 3 : printf("Positive!\n");break;
case 4 : printf("As I see it Yes.\n");break;
case 5 : printf("Certainly!\n");break;
case 6 : printf("Negative!\n");break;
case 7 : printf("Don't Count on it.\n");break;
case 8 : printf("You don't want to know, trust me.\n");break;
case 9 : printf("I can't say right now.\n");break;
// No need for default because you'll never get to it
// (just because of how we implemented this software)
// default : printf("Cannot be determined right now");break;
}
}