Try the following:
CODE
//These two libraries must be used when you want random numbers.
#include<iostream>
#include <stdlib.h>
#include <time.h>
#include <string>
#include <limits>
using namespace std;
bool play = true;
int choice;
char useless[200];
int useless2;
int useless3;
char again;
int main()
{
while (play == true)
{
cout<< "welcome to my Project you will either get your fortune or you stock advice" << endl;
cout<< "chooose one" << endl;
cout<< "1. fourtune teller" << endl;
cout<< "2. stock advice" << endl;
cin>> choice;
if (choice == 1)
{
cout << "hi and welcome to my fortune teller" << endl;// describing how its going to work
cout << "it works like a magic eight ball program" << endl;
cout << "please enter in a question and it will tell you the answer.";
cin.clear();
cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
cin.getline(useless, 200);
cout << flush;
srand((unsigned)time(NULL));
int theNumber;
theNumber = 1 + rand() % 4;
if (theNumber == 1)
{
cout<<"No way."<<endl;
}
if (theNumber == 2)
{
cout<<"Most likely, yes."<<endl;
}
if (theNumber == 3)
{
cout<<"Try again tomorrow."<<endl;
}
if (theNumber == 4)
{
cout<<"Yes, I believe so!"<<endl;
}
cout << "Do you wish to start again? (Y/N)\n";//asking them if they want to start again.
cin >> again;//storing their answer.
if (again == 'Y' || again == 'y')// declarring their answer in either case
{
system("cls");// clearing the screen
} else if (again == 'N' || again == 'n')// declarring their answer in either case
{
system("cls");// clearing the screen
play = false;// ending the loop
cout << "Thank you for using my fourtune teller I know it gave you the right answer.!\n";
}
}
if (choice == 2)
{
cout<<"you chose stock advice" << endl;
cout<<"enter in how many stocks you own" << endl;
cin>> useless2;// storing their data but not using it.
cin.clear();
cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
cout<< "enter in the estimated total value of you stocks" << endl;
cin>> useless3;// storing their data but not using it.
cin.clear();
cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
srand((unsigned)time(NULL));
int theNumber;
theNumber = 1 + rand() % 3;
switch (theNumber)
{
case 1:
cout<<"You should definitely buy!"<<endl;
break;
case 2:
cout<<"Sell! Sell! Sell!"<<endl;
break;
case 3:
cout<<"Heck if I know. Go ask your stock broker."<<endl;
break;
default:
break;
}
cout << "Do you wish to start again? (Y/N)\n";//asking them if they want to start again.
cin >> again;//storing their answer.
if (again == 'Y' || again == 'y')// declarring their answer in either case
{
system("cls");// clearing the screen
}else if (again == 'N' || again == 'n')// declarring their answer in either case
{
system("cls");// clearing the screen
play = false;// ending the loop
cout << "Thank you for using my stock advice i hope it serves you well!\n";// thanking them for playing
}
}
}
return 0;
}
The problem with mixing inputs of numbers and strings is that when you
cin << number the stream leaves the CR in the buffer, so that when you input a string it stops at the CR and gives you an zero length string with no wait. I am sure that if I were not so tired I would know WHY it does things this way, but at the moment it just seems like a bug. But that is the way it works.
To solve this use two lines:
CODE
cin.clear() //clears the input buffer..
cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); // Will ignore all CR's until EOF (well EO-Stream at least).