Questinator

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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <string>
#include<iostream>
using namespace std;

int main()
{srand(time(0));
string t;
char playAgain='y';
cout <<"I am the Questionator! Ask me any Question and I will Answer!" << endl;
cout <<"(Yes/No only)"<<endl;
      while (playAgain !='n')
{
      int x =1+rand()%8;
      cout <<" "<<endl;
      cout << "Ask the Question: "<<endl;
      cout <<" "<<endl;
      getline (cin,t);
      cout <<" "<<endl;   
  if (x == 1)

  {
        cout << "Certainly!"<<endl;
        }
if (x == 2)
{
    cout << "Not really!"<<endl;
}   
 
 if (x == 3)
{
    cout << "Probably not!"<<endl;
} 
 
if (x == 4)
{
      cout << "Maybe!"<<endl;
}

if (x ==5)
{ 
      cout << "Probably"<<endl;
} 
 
 if (x ==6)
{ 
       cout << "No way!"<<endl;      
}  
 
 if (x ==7)
{
    cout << "Possibly!"<<endl;
} 
 
 if (x ==8)
{
    cout << "Unlikely"<<endl;
}   
do{
cout << "Would you like to ask another question? y/n: ";
	    cin >> playAgain;
	    cout <<" "<<endl;
        }while (playAgain !='y' && playAgain !='n');
}
    
cout <<" "<<endl;
cout << "Thank you for playing a game by Anmol Sethi and Matthew Sonne!" << endl; 
system ("pause");
}


Could someone help me with this code. After it loops it wont let me ask a question?
Lines 58-62 look suspect. First, they will exit when you hit y or n, doing the same thing either way. Second, the cin >> on line 60 leaves junk in the input buffer, so your later getline() will not work correctly.
So how do I fix this?
TY I FIXED IT WITH YOUR HELP. THANK YOU! UR MY NEW BEST BUDDY :D.
Topic archived. No new replies allowed.