Thread: Crashing while using random numbers

  1. #1
    Registered User
    Join Date
    Oct 2011
    Location
    Ottawa
    Posts
    17

    Crashing while using random numbers

    Hey everyone,

    So, I'm in the middle of writing a program in C focusing on the use of random numbers, specifically their applications to dice and guessing games. However, every time I run my program so far (all previous programs have worked fine), the program simply stops working, and I receive the message "A problem caused the program to stop working correctly. Windows will close the program and notify you if a solution is available". This pops up in a separate window. I am using CodeBlocks.
    Any suggestions/previous experience?

    Much Thanks,
    Braydon

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    That line right there. Yeah, fix that one.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Since you are on Windows and posted no real information needed to find the cause; I go with shutdown and restart the computer.

    Tim S.

  4. #4
    Registered User
    Join Date
    Oct 2011
    Location
    Ottawa
    Posts
    17
    This problem has been occurring for a couple days, but only for this program. My other programs still works fine. I am still VERY new to programming, so this may just be problems with syntax, so I have the section of my code which is having the problem. I have code before this, including the appropriate libraries, but all of that is working fine. The program stops working after the user inputs their guess.

    Code:
    int PlayingDice()
    {
    int uGuess, Roll;
    
    
    printf("\nYou have chosen to play dice! \nChoose a number between 2 and 12, and if the dice roll your number, you win! \nPlease enter your number now: ");
    scanf("%d", uGuess);
    Roll=2+rand()%11;
    
    
    if (Roll==uGuess)
    printf("\nCongratulations! You won!");
    
    
    else
    printf("\nSorry! You lost!");
    Hopefully this makes things a little clearer.
    Braydon

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Turn on your compiler's warnings.
    Code:
    scanf("%d", uGuess);
    You forgot the & there. The arguments scanf takes must be addresses.


    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    Registered User
    Join Date
    Oct 2011
    Location
    Ottawa
    Posts
    17
    You're beautiful and I'm an idiot! Thank you so much!

    Braydon

  7. #7
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by daynorb View Post
    Hey everyone,

    So, I'm in the middle of writing a program in C focusing on the use of random numbers, specifically their applications to dice and guessing games. However, every time I run my program so far (all previous programs have worked fine), the program simply stops working, and I receive the message "A problem caused the program to stop working correctly. Windows will close the program and notify you if a solution is available". This pops up in a separate window. I am using CodeBlocks.
    Any suggestions/previous experience?

    Much Thanks,
    Braydon
    On the bottom of that window is a small button with 2 down arrows... when you point to it the help text says ... "More information"

    The explaination is buried in "more information"...

    It's probably code C0000005 ... a memory access violation (about 4/5 of them are)

    Win7 really sucks at handling unhandled exceptions, trying to babysit the user instead of informing the programmer.

    Post your code and the error report... lets see what's up...

    EDIT: Never mind.

  8. #8
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by stahta01 View Post
    Since you are on Windows and posted no real information needed to find the cause; I go with shutdown and restart the computer.

    Tim S.
    That won't do anything...
    That particular window comes up when there's been an exception that no other exception handler as handled. That's the unhandled exception handler... Restarting the machine does nothing in that case.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Random numbers not random?
    By yacek in forum C Programming
    Replies: 6
    Last Post: 10-08-2010, 06:57 PM
  2. Random Numbers
    By kris.c in forum C Programming
    Replies: 16
    Last Post: 06-14-2006, 05:44 AM
  3. Random Numbers
    By darthbob88 in forum C Programming
    Replies: 2
    Last Post: 02-11-2006, 03:05 PM
  4. Replies: 4
    Last Post: 11-16-2004, 07:29 AM
  5. random numbers
    By Micko in forum C++ Programming
    Replies: 2
    Last Post: 03-15-2004, 07:17 AM

Tags for this Thread