#include <iostream>
#include "dice.h"
usingnamespace std;
int main() {
Dice coin(2);
int loop;
int counter[2];
int coinValue;
for (loop = 1; loop < 2; loop++) {
counter[loop] = 0;
}
// 10,000 times
for (loop = 0; loop < 10000; loop++) {
coinValue = coin.Roll();
if (coinValue == 1) counter[coinValue]++;
elseif (coinValue == 2) counter[coinValue]++;
}
cout << "Coin Toss Count\n----------------------\n\n";
for (loop = 1; loop < 2; loop++) {
cout << "Flipped a " << loop << ", " << counter[loop] << " times in 10,000 flips.\n";
}
cout << endl;
return 0;
}
I'm trying to use a class for a dice program as a coin toss simulator. For some reason, every time I try to run the program it says that there is a corruption of a stack of some kind surrounding "counter". What might be causing that?
Also, how would I go about making it so that the program read the longest series of heads or tails in a simulation of 10,000 flips?
Any help would be appreciated. Thanks.
The first thing that I see is wrong, is you are trying to increase the value in array segment 2, which actually doesn't exist. When you created counter[2], you have a counter[0] and counter[1]. Arrays start with zeroes. The best thing I can think of to remedy that, is make coinValue a bool, which is either a 0 or a 1. When you flip the coin, a 0 could be heads, and 1, tails. . Hope this helps..
The first thing that I see is wrong, is you are trying to increase the value in array segment 2, which actually doesn't exist. When you created counter[2], you have a counter[0] and counter[1]. Arrays start with zeroes. The best thing I can think of to remedy that, is make coinValue a bool, which is either a 0 or a 1. When you flip the coin, a 0 could be heads, and 1, tails. . Hope this helps..