Thread: newbie!! help!

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    16

    Question newbie!! help!

    I'm trying to write this simple two dice game to get better at programming but a keep getting 'segmentation fault'
    this is the code:
    #include <stdio.h>

    main ()
    {
    srand (time());
    int Die1= (rand() % 6) + 1;
    int Die2= (rand() % 6) + 1;
    int sum;

    printf ("\nThe dices roll\n");
    printf ("Dice one and two are: %d,\t%d",Die1,Die2);

    sum= (Die1 + Die2);

    printf ("\n%d",sum);

    if ((sum == 7) || (sum == 11))
    printf ("\nYOu guess right");
    else
    printf ("\nYou guess wrong");
    return (0);
    }

    can anyone tell what is wrong ??
    thanx

  2. #2
    Registered User
    Join Date
    May 2003
    Posts
    148
    Code:
    #include <stdio.h>
    #include <stdlib.h> /* Include all needed header */
    #include <time.h>
    
    int main () /* main returns int,implicit int is deprecated */
    {
    	srand (time(0)); /* time takes one parameter */

  3. #3
    Banned
    Join Date
    May 2003
    Posts
    124
    You forgot to include <stdlib.h> for rand() and srand() and <time.h> for time().

    >srand (time());
    Should be:
    srand (time( NULL ));

    P.S I think you should ask for the guess of the user.

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    And read this please.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #5
    pest
    Guest
    thanx i'll do that

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. getting to grips with allegro and ms vc++ (newbie)
    By jimjamjahaa in forum C++ Programming
    Replies: 4
    Last Post: 11-18-2005, 07:49 PM
  2. Newbie in problem with looping
    By nrain in forum C Programming
    Replies: 6
    Last Post: 11-05-2005, 12:53 PM
  3. Newbie Programmer
    By Extropian in forum C++ Programming
    Replies: 3
    Last Post: 05-18-2004, 01:17 PM
  4. Some help for a newbie?
    By Ilmater in forum C++ Programming
    Replies: 23
    Last Post: 04-19-2004, 07:44 PM
  5. Newbie Game Develpoers Unite!
    By Telenosis in forum Game Programming
    Replies: 10
    Last Post: 06-22-2002, 02:02 PM