This loop is supposed to prompt the user for values from 1 to 6 until it has 5 values. It works for every other number, but if I enter a 2 it says "Thread1: breakpoint 1.1" then doesn't crash but stops accepting inputs. I am new to C++ so I may be missing something obvious syntax-wise.
int userInput = 0;
int numUserIns = 0;
int diceRoll1, diceRoll3, diceRoll2, diceRoll4, diceRoll5, diceRoll6;
int numOnes = 0;
int numTwos = 0;
int numThrees = 0;
int numFours = 0;
int numFives = 0;
int numSix = 0;
while (numUserIns <= 5){
cout << "Enter a number from 1 to 6\n";
cin >> userInput;
if (userInput == 1){
diceRoll1 = userInput;
numUserIns++;
numOnes++;
} else if (userInput == 2){ //not accepting two as input
diceRoll2 = userInput; //This line causes error: Thread 1: breakpoint 1.1
numUserIns++;
numTwos++;
} else if (userInput == 3){
diceRoll3 = userInput;
numUserIns++;
numThrees++;
} else if (userInput == 4){
diceRoll4 = userInput;
numUserIns++;
numFours++;
} else if (userInput == 5){
diceRoll5 = userInput;
numUserIns++;
numFives++;
} else if (userInput == 6){
diceRoll6 = userInput;
numUserIns++;
numSix++;
} else if (userInput < 1 || userInput > 6){
cout << "invalid input";
break;
}
}
Aucun commentaire:
Enregistrer un commentaire