It keeps asking "do you want to play again"

Jan 17, 2012 at 1:31am
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
#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

int main()
{
    int start ;
    int finish;
    bool PlayAgain = 0;
    char PlayAgainAnswer;

    do {

      do {
        cout << "what number would you like the computer to count to?: ";
        cin >> finish;
        cout << "what number would you like the computer to start at?: ";
        cin >> start;
        if (start >= finish)
        cout << "The number you start at has to be smaller then the number your counting to. \n";
      } while (start >= finish);

      while (start <= finish){
        cout << start << endl;
        start = start + 1;
      }

      do {
        cout << "Do you wanna play again? (y/n): ";
        cin >> PlayAgainAnswer;
      } while (PlayAgainAnswer != 'y' || 'n' || 'Y ' || 'N');

      if (PlayAgainAnswer == 'y' || 'Y')
        bool PlayAgain = 1;

      if (PlayAgainAnswer == 'n' || 'N')
        bool PlayAgain =  0;

    } while (PlayAgain == 1);

    return 0;
}


when i run the program it always asks me "Do you wanna play again? (y/n):" no matter what i type in
Jan 17, 2012 at 1:37am
closed account (zb0S216C)
This will prove useful: http://www.cplusplus.com/forum/general/59096/

Wazzak
Jan 17, 2012 at 2:43am
i still cant get it to work :/
Jan 17, 2012 at 3:55am
You should not ask the same question in two different threads. http://cplusplus.com/forum/beginner/59540/
Jan 17, 2012 at 4:00am
See my answer in your other thread.

http://www.cplusplus.com/forum/beginner/59540/
Jan 17, 2012 at 4:20am
In addition to thepedestrian's solutions in the other thread:

1) Change the 'Y ' (space) on line 33 to 'Y' (no space).
2) Get rid of "bool" in front of PlayAgain on lines 36 and 39... otherwise, you're defining two new objects, limited in scope to each if block, not referencing the original variable.
Topic archived. No new replies allowed.