Quick Logic Fix

Oct 21, 2015 at 11:57pm
Hey! I was wondering whether anyone could find the error here? The user inputs their choice and depending on their choice, they are to input which object they are to display. However, whenever the user inputs something other than y for yes, loop continues to move on, which is not what is desired. If a user types on no, for example, i want it to end. How can I fix it?

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
  bool validChoice = false;
        bool validate = false;
        char choice;
        int i;

        do{
                cout << "Would you like to see any of the polygons you've created? Enter y for yes, n for no." << endl;
                cin >> choice;

                if ('Y'|| 'y'){
                        do{
                                cout << "Which object would you like to see?" << endl;
                                cin >> i;

                                if ( i <= N){
                                        pol[i-1] -> DrawPolygon();
                                        validate = true;
                                        validChoice = true;
                                }

                        }while(!validate);
                }

        }while(!validChoice);

Oct 22, 2015 at 3:17am
if (choice=='Y' || choice == 'y')
Topic archived. No new replies allowed.