I am in the process of writing a little Yahtzee program out of boredom. However, I have stumbled upon a little error that I cannot seem to solve. I used an integer array to hold the values of six dice. After displaying the values once, then changing some of those values, then displaying again results in the following error:
Debug Error!
Program: ... Studio 2008\Projects\Yahtzee\Debug\Yahtzee.exe
Module: ... Studio 2008\Projects\Yahtzee\Debug\Yahtzee.exe
File:
Run-Time Check Failure #2 - Stack around the variable 'dice' was corrupted.
When you first fill the dice array with random rolls, your for loop should use i < 5, not i <= 5.
Ironically, you have that set up properly in your second loop that conditionally rerolls.
When you first fill the dice array with random rolls, your for loop should use i < 5, not i <= 5.
Ironically, you have that set up properly in your second loop that conditionally rerolls.
Haha, stupid logical error.
Make sure to always call cin.ignore(); after using a "cin >>" command.
What exactly does that do? In both my C++ classes we never learned to do that.
What exactly does that do? In both my C++ classes we never learned to do that.
This will ignore the trailing '\n' that is present if you use >> with std::cin and the user hits enter (assuming there is one, otherwise it will ignore 1 character).
I would suggest used std::getline() instead, which will get an entire line up to the first '\n' for you, which you can then parse yourself.