I have an assignment to make the sorry board game and in my code, I keep getting an automatic loop but I'd like for it to say hit enter key to roll your dice as I need to for the assignment but I have no clue on how to do that and couldn't find anything, also it repeats the same number a bunch of times before it switches numbers which each player should be getting a different number each time instead of the same number 20 times then a different number. How do I go at fixing both of these?
[enter image description here][1]
https://gyazo.com/9f0d48e035cf19bbb7a64662d0acf346
idk if I did the image thing correctly so there's the gyazo link to
#include <iostream>
#include <string>
#include <ctime>
#include <iomanip>
using namespace std;
int RandomNumber()
{
srand(time(NULL));
return rand() % 11+2;
}
bool CheckWinner(int i)
{
return (i == 50);
}
int main() {
switch (RandomNumber())
{
}
int NumOfPlayer;
cout << "Enter Number of Players (2-4): ";
cin >> NumOfPlayer;
while (NumOfPlayer < 2 && NumOfPlayer > 4){
cout << "Please insert a number of players with a minimum of 2 or a max of 4: ";
cin >> NumOfPlayer;
}
int Spaces[50];
int *playerPos = new int[NumOfPlayer];
for (int i = 0; i<NumOfPlayer; i++)
playerPos[i] = 0;
bool win = false;
int winner;
while (!win)
{
for (int j = 0; j<NumOfPlayer; j++)
{
cout << "Player "<< j + 1 << " turn " << endl;
int num = RandomNumber();
cout << "You rolled: " << num << endl;
switch (num)
{
case 2:
{
if (playerPos[j] + 2 <= 50)
playerPos[j] += 2;
if (CheckWinner(playerPos[j]))
{
win = true;
winner = j + 1;
}
break;
}
case 3:
{
if (playerPos[j] + 3 <= 50)
playerPos[j] += 3;
if (CheckWinner(playerPos[j]))
{
win = true;
winner = j + 1;
}
break;
}
case 4:
{
if (playerPos[j] + 4 <= 50)
playerPos -= 1;
if (CheckWinner(playerPos[j]))
{
win = true;
winner = j + 1;
}
break;
}
case 5:
{
if (playerPos[j] + 5 <= 50)
playerPos += 5;
if (CheckWinner(playerPos[j]))
{
win = true;
winner = j + 1;
}
break;
}
case 6:
{
if (playerPos[j] + 6 <= 50)
playerPos += 6;
if (CheckWinner(playerPos[j]))
{
win = true;
winner = j + 1;
}
break;
}
case 7:
{
int k = 0;
while (k < NumOfPlayer)
{
if (k != j && playerPos[k] > playerPos[j])
playerPos[j] = playerPos[k];
k++;
cout << "You swapped with the lead player!" << endl;
}
if (CheckWinner(playerPos[j]))
{
win = true;
winner = j + 1;
}
break;
}
case 8:
{
if (playerPos[j] + 8 <= 50)
playerPos[j] += 8;
if (CheckWinner(playerPos[j]))
{
win = true;
winner = j + 1;
}
break;
}
case 9:
{
if (playerPos[j] + 9 <= 50)
playerPos[j] += 9;
if (CheckWinner(playerPos[j]))
{
win = true;
winner = j + 1;
}
break;
}
case 10:
{
if (playerPos[j] + 10 <= 50)
playerPos[j] += 10;
if (CheckWinner(playerPos[j]))
{
win = true;
winner = j + 1;
}
break;
}
case 11:
{
int k = 0;
while (k < NumOfPlayer)
{
if (k != j && playerPos[k] < playerPos[j])
playerPos[j] = playerPos[k];
k++;
}
if (CheckWinner(playerPos[j]))
{
win = true;
winner = j + 1;
}
break;
}
case 12:
{
playerPos[j] = 0;
if (CheckWinner(playerPos[j]))
{
win = true;
winner = j + 1;
}
break;
}
}
}
}
cout << "Winner is Player: " << winner;
return 0;
}```
[1]: https://i.stack.imgur.com/ign0e.png