Classing problem

How do i get this to randomly throw out 1 of the text in the eightBall class

#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <string>

using namespace std;

int main()


{
string iSecret;
string eightBall[15];
string question;
cout << "Welcome, my name is 8ball ask me a yes and no question." << endl;
cin >> question;
cout << eightBall[15];



eightBall[0] ="Yes, in due time.";
eightBall[1] ="My sources say no.";
eightBall[2] ="Definitely not.";
eightBall[3] ="Yes.";
eightBall[4] ="You will have to wait.";
eightBall[5] ="I have my doubts.";
eightBall[6] ="Outlook so so.";
eightBall[7] ="Looks good to me!";
eightBall[8] ="Who knows?";
eightBall[9] ="Looking good!";
eightBall[10] ="Probably.";
eightBall[11] ="Are you kidding?";
eightBall[12] ="Go for it!";
eightBall[13] ="Don't bet on it.";
eightBall[14] ="Forget about it.";

srand (time(NULL));
iSecret = rand() % 15 + 1;
return 0;
}
You've already done most of the work here.
If you don't care about storing the value of the random output just do this

cout << eightBall[rand() % 15 + 1];

but if you do want to, then store it in iSecret

1
2
iSecret = eightBall[rand() % 15 + 1]
cout << iSecret


it's strange to have a variable, iSecret, starting with an i (which normally represents an int) which is a string. Are you sure iSecret wasn't meant to be an int and store the position in the array of the random element, not the string itself?
Doesn't seem to work quirky unless im putting those lines into the wrong ones

#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <string>

using namespace std;

int main()


{
string iSecret;
string eightBall[15];
string question;
cout << "Welcome, my name is 8ball ask me a yes and no question." << endl;
cin >> question;
cout << iSecret;



eightBall[0] ="Yes, in due time.";
eightBall[1] ="My sources say no.";
eightBall[2] ="Definitely not.";
eightBall[3] ="Yes.";
eightBall[4] ="You will have to wait.";
eightBall[5] ="I have my doubts.";
eightBall[6] ="Outlook so so.";
eightBall[7] ="Looks good to me!";
eightBall[8] ="Who knows?";
eightBall[9] ="Looking good!";
eightBall[10] ="Probably.";
eightBall[11] ="Are you kidding?";
eightBall[12] ="Go for it!";
eightBall[13] ="Don't bet on it.";
eightBall[14] ="Forget about it.";

srand (time(NULL));
iSecret = eightBall[rand() % 15 + 1];
return 0;
}
I don't understand what you want.
Why not just add cout << iSecret?
This would make more sense though:
1
2
3
4
5
6
int iSecret;
...
srand(time(NULL));
iSecret = rand()%15+1;
cout << eightBall[iSecret];
...

Or you could even take out the intermediate step of assigning iSecret and do away with one more variable.
Topic archived. No new replies allowed.