Help with do while magic 8 ball

The again after my while is undefined and I am not sure how to fix it. I could you some help.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
  #include <iostream>
#include <cstdlib>
#include <string>

using namespace std;

int main()
{
	cout << " think of a question ";
   cin.ignore();
  cin.get();
  cout << " Your answer is: \n";
  
  
   int out;
   out = rand()%20;
  
   do
   {
   switch(out)
  {
   case 0 : cout << " It is certain \n";break;
   case 1 : cout << " It is decidedly so \n";break;
   case 2 : cout << " Without a doubt \n"; break;
   case 3 : cout << " Yes, definitely \n";break;
   case 4 : cout << " You may rely on it \n";break;
   case 5 : cout << " As I see it, yes \n";break;
   case 6 : cout << " Most likely \n";break;
   case 7 : cout << " Outlook good \n";break;
   case 8 : cout << " Yes \n";break;
   case 9 : cout << " Signs point to yes \n";break;
   case 10 : cout << " Reply hazy try again \n";break;
   case 11 : cout << " Ask again later \n";break;
   case 12 : cout << " Better not tell you now \n";break;
   case 13 : cout << " Cannot predict now \n";break;
   case 14 : cout << " Concentrate and ask again \n";break;
   case 15 : cout << " Don't count on it \n";break;
   case 16 : cout << " My reply is no \n";break;
   case 17 : cout << " My sources say no \n";break;
   case 18 : cout << " Outlook not so good \n";break;
   case 19 : cout << " Very doubtful \n";break;
   }
   char again = 'N';
    cout << " Do you want to ask again? ";
		   cin >> again;
 
   }
  while ( again == 'Y' || again == 'y');
	  
   
}


again goes out of scope at line 47. Move the definition of again to before the do/while loop.

BTW, you never seed the random number generator. You program is going to return the same sequence of random numbers every time you run it.
http://www.cplusplus.com/reference/cstdlib/srand/
Sorry for the lack of response my classes have kept me busy. When you say never seed the random number generator, do you mean that i did not seed my program or that you are not suppose to seed a random number generator?
If you want a different sequence of random numbers each time you run your program, you need to call srand() to seed the RNG.

Since you're not calling srand(), you're going to get the same random number and therefore the same answer every time you run your program. You should call srand() once at the top of main().

That is what i thought you meant but I figured i ask for clarification. I do appreciate the help you have given me.
Topic archived. No new replies allowed.