Not exiting While loop

Hey guys. This is a portion of code that I've been trying to fix, and I know I'm missing something blatantly obvious and I've recreated this same thing with a simpler program, But for some reason this I can't exit this while loop. Basically I have While (roll != 1 || input != "hold") but whenever I roll a 1 it doesn't exit. Can you guys spot what I'm missing? (this is only a problem for game 1 so I only provided that code)

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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>


using namespace std;

int main()
{
	int gameChoice;
	int score;

	cout << "Please select what you want to do." << endl;
	cout << "Input 1 to play Pig, Input 2 to play Blackjack, and input 3 to exit" << endl;

	cin >> gameChoice;

	if (gameChoice == 1) //start PIG
	{
		int turnPoints = 0;
		int compScore = 0;
		int userScore = 0;
		int roll = 0;
		int turn = 1;
		string input;


		cout << "Welcome to PIG! Be the first to reach 100." << endl;

		while (compScore != 100 || userScore != 100)
		{
			cout << "Please input 'roll' to roll the dice" << endl;

			cin >> input;

			if (input == "roll") //First roll of two dice (player)
			{


				while (roll != 1 || input != "hold")
				{

					srand(time(0));
					roll = 1 + (rand() % 6);

					cout << "You rolled a " << roll << endl;

					
						turnPoints = roll + turnPoints;

						cout << "You're current score is " << turnPoints << endl;
						cout << "Would you like to hold or roll again? " << endl;
						cout << "Input 'role' to roll again, or input 'hold' to hold and end your turn." << endl;
						cin >> input;

				}

				if (roll == 1)
				{
					cout << "You have lost all of your points this turn." << endl;
					turnPoints = 0;

					cin.ignore();
					cin.get();
				}

				if (input == "hold")
				{
					userScore = turnPoints + userScore;
					cout << "Your total score is now " << userScore << endl;
				}


			}

		}

		cin.ignore();
		cin.get();
		
	}
	system("pause");
	return 0;
}
Last edited on
You exit the while loop only if both conditions are false, so you need to roll 1 and hold. If you don't hold, input!="hold" is true, and you continue. I think you want to use && instead of ||.
Also, you need to reset roll and input variables while in the loop on line 31.
Topic archived. No new replies allowed.