I'm having difficulties with this code...it won't randomize the answer for some reason

#include <string>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <fstream>
#include <ctime>
#define down8 "\n\n\n\n\n\n\n\n"
#define down7 "\n\n\n\n\n\n\n"
#define down5 "\n\n\n\n\n"
#define over4 "\t\t\t\t"
#define over3 "\t\t\t"
#define over2 "\t\t"


void welcome (); 
void splash ();

using namespace std;

int main(){


string question;
ifstream inputFile;
const int SIZE = 20;
string fileName, answerGuess[SIZE];
int random;
unsigned int seed = time(NULL);

srand(seed);

//opens the welcome and splash screen
splash();
welcome();

//random generator
random = 0 + rand() % 30;

//user enters file name
system("CLS");
cout << down5 << down5 << over2 <<"Please enter he file name: ";
cin >> fileName;

//opens file
inputFile.open(fileName.c_str());

//kick out of file if not found
if (inputFile)
{

//get fortunes from the file
for (int i = 0; i < SIZE; i++)
{
    getline(inputFile, answerGuess[i]);
}
inputFile.close();

//display
system("CLS");
cout << down8;
cout << over3 << "Ask the magic 8 ball a yes or no question,";
cout << over4 << "if you dare...." << endl;
cout << over4;
getline(cin, question);


for (int i = 0; i < 20; i++)
{
    getline(cin, question);
    cout << over3 << answerGuess[random] << endl;
}

system("CLS"); 
cout << endl;
cout << over3 << "The fortune teller says..."
     << endl << endl;


system("CLS");
if (random > SIZE - 1)
{
    cout << over3 << "None of these...Try again." << down5 << endl;
}
else
{
    cout << over3 << answerGuess[random] << down5 << endl;
}

}
else
{
cout << over4 << "File \"" << fileName << "\" was not found!";
cout << over4 << "Please restart the program and try again";
cout << down5;
}
cout << down5;
system("PAUSE");

return EXIT_SUCCESS;
}

Edited 1 Year Ago by pritaeas: Fixed markdown.

You generate one random number and then you use that same number for your whole program. Is that what you meant to do?

Edited 1 Year Ago by Moschops

This article has been dead for over six months. Start a new discussion instead.