Anable
Newbie
- Joined
- Nov 21, 2003
- Messages
- 270
- Reaction score
- 0
I have a magic 8 ball program that I've been working on and the whole thing works fine except that when it asks if you want to go again, it assumes your input and goes directly to your answer. Now I think this is happening because the array that the answer is stored in already has a value associated with it and doesn't bother asking you for new information to put in it. How do I fix this? Is there a way to clear the information in an array after you're done with it or am I approaching it from completely the wrong angle? Here's the code if it helps out any:
Thanks for the help!
Code:
#include <iostream.h>
#include <stdlib.h>
#include <time.h>
#define HIGH 10
#define LOW 1
void meaningless();
unsigned long timeseed();
void output(int number);
void again();
int main()
{
unsigned long result;
cout << endl << endl << "Magic 8-ball as performed by anable" << endl << endl << endl;
meaningless();
result = timeseed();
output(result);
again();
cout << endl;
return 0;
};
void meaningless() //This eats the characters for the question and does nothing with it
{
char question[200];
cout << "What is your question? ";
cin.getline(question,200);
};
unsigned long timeseed() //This creates a unique seed for rand
{
int number;
time_t seconds; //Creates time variable
time(&seconds); //Takes system time and puts it into variable "seconds"
srand((unsigned int) seconds); //Dunno what it does but I think I need it
number = rand() % (HIGH - LOW + 1) + LOW; //Ensures random number is between 1 and 10
return number;
};
void output(int number)
{
switch (number)
{
case 1:
cout << "Signs point to yes." << endl;
break;
case 2:
cout << "Without a doubt." << endl;
break;
case 3:
cout << "My sources say no." << endl;
break;
case 4:
cout << "Outlook not so good." << endl;
break;
case 5:
cout << "Better not tell you now." << endl;
break;
case 6:
cout << "Ask again later." << endl;
break;
case 7:
cout << "Don't count on it." << endl;
break;
case 8:
cout << "Who knows?" << endl;
break;
case 9:
cout << "Forget about it." << endl;
break;
case 10:
cout << "Probably." << endl;
break;
default:
cout << "Ah..you shouldn't be seeing this..." << endl;
}
};
void again() //Checks to see if you want to run the program again.
{
char buffer;
cout << "Would you like to ask another question? (y/n) ";
cin >> buffer;
if (buffer == 'y')
{
main();
}
else
{
exit(0);
}
}
Thanks for the help!