I have a small program that causes the "This program has performed an illegal operation and will be shut down." box to pop up everytime I run it. Also, the program doesn't show any output so I dont think it even ran. MSVC++ 6.0 does not show any errors or warnings (I have the warning level set to level 3). Here is my program:
Header File (RND.H)
// This seeds the random numbers...
void Startup()
{ srand( (unsigned)time( NULL ) ); }
int Dice (int numDie = 1, int numSides = 6, int numAdd = 0)
{
int Total = 0;
if ((numDie > 0) && (numSides > 0))
{
int x;
for (int i = 0; i < numDie; i++)
{
x = (rand()%numSides) + 1;
Total = Total + x;
}
Total = Total + numAdd;
}
return Total;
}
And this is the RND.CPP file...
#include "stdafx.h"
#include <iostream.h>
#include <stdlib.h>
#include <time.h>
#include "RND.h"
int main(int argc, char* argv[])
{
Startup();
int total[5];
int x;
for (int tyu = 0; tyu < 6; tyu++) total[tyu] = 0;
for (int ctr = 0; ctr < 1001; ctr++)
{
x = Dice();
total[(x+1)]++;
for (int ctr2 = 0; ctr2<6;ctr2++)
cout << "Side " << ctr2 << ": " << total[(ctr2+1)] << " / " << (ctr / total[(ctr2+1)]) << "\t";
cout << "\n";
}
return 0;
}
Here is the text in the windows error box (I dont know if this helps or not):
RND caused a divide error in module RND.EXE at 015f:004011c7.
Registers:
EAX=00000000 CS=015f EIP=004011c7 EFLGS=00010297
EBX=00560000 SS=0167 ESP=0066fd84 EBP=0066fdf8
ECX=00000000 DS=0167 ESI=816cb73c FS=342f
EDX=00000000 ES=0167 EDI=0066fdf8 GS=0000
Bytes at CS:EIP:
f7 7c 8d f0 50 68 2c 80 42 00 8b 55 dc 8b 44 95
Stack dump:
00428030 00000000 816cb73c 00560000 cccccccc cccccccc cccccccc cccccccc cccccccc cccccccc cccccccc cccccccc cccccccc cccccccc cccccccc cccccccc
There it all is... I dont have the faintest idea whats wrong with my prog. Thanks in advance for your help.
Skywise
Header File (RND.H)
// This seeds the random numbers...
void Startup()
{ srand( (unsigned)time( NULL ) ); }
int Dice (int numDie = 1, int numSides = 6, int numAdd = 0)
{
int Total = 0;
if ((numDie > 0) && (numSides > 0))
{
int x;
for (int i = 0; i < numDie; i++)
{
x = (rand()%numSides) + 1;
Total = Total + x;
}
Total = Total + numAdd;
}
return Total;
}
And this is the RND.CPP file...
#include "stdafx.h"
#include <iostream.h>
#include <stdlib.h>
#include <time.h>
#include "RND.h"
int main(int argc, char* argv[])
{
Startup();
int total[5];
int x;
for (int tyu = 0; tyu < 6; tyu++) total[tyu] = 0;
for (int ctr = 0; ctr < 1001; ctr++)
{
x = Dice();
total[(x+1)]++;
for (int ctr2 = 0; ctr2<6;ctr2++)
cout << "Side " << ctr2 << ": " << total[(ctr2+1)] << " / " << (ctr / total[(ctr2+1)]) << "\t";
cout << "\n";
}
return 0;
}
Here is the text in the windows error box (I dont know if this helps or not):
RND caused a divide error in module RND.EXE at 015f:004011c7.
Registers:
EAX=00000000 CS=015f EIP=004011c7 EFLGS=00010297
EBX=00560000 SS=0167 ESP=0066fd84 EBP=0066fdf8
ECX=00000000 DS=0167 ESI=816cb73c FS=342f
EDX=00000000 ES=0167 EDI=0066fdf8 GS=0000
Bytes at CS:EIP:
f7 7c 8d f0 50 68 2c 80 42 00 8b 55 dc 8b 44 95
Stack dump:
00428030 00000000 816cb73c 00560000 cccccccc cccccccc cccccccc cccccccc cccccccc cccccccc cccccccc cccccccc cccccccc cccccccc cccccccc cccccccc
There it all is... I dont have the faintest idea whats wrong with my prog. Thanks in advance for your help.
Skywise