Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Da cobra

get a memory error

This topic is 5571 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

can som1 pls try this code or tell me why I get a memory error when I run it?
        

#include <time.h>

#include <stdlib.h>

#include <iostream.h>

void main()
{
	// *** initialisation ***


	int dice[10] ;
	int counter = 0 ;
	int three = 0 ;
	int six = 0 ;

	// *** generate 10 random numbers ***

	for (counter = 1; counter <= 10; counter++)
	{
		srand ((unsigned)time(NULL)) ;
		dice[counter] = rand()%6 + 1;
		if (dice[counter] == 3)
		{
			three = three + 1 ;
		}
		else 
			if (dice[counter] == 6)
			{
				six = six + 1 ;
			}
		
	}
	
	// *** output ***

	system("cls") ;
	for (counter = 1; counter <= 10; counter++)
	{
		cout << "Dice " << counter << " = " << dice[counter] << endl ;
	}
	cout << endl ;
	cout << "thrown a 3 : " << three << endl ;
	cout << "thrown a 6 : " << six << endl ;
	
}

        
thanx in advance for any help [edited by - Da Cobra on March 18, 2003 11:37:41 AM]

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Instead of counter <= 10, replace with counter < 10. If you have int dice[10], there is no dice[10]. That defines 10 elements in the array, which would be dice[0..9]. That should fix it.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!