Thread: can someone help me get started?

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    41

    Unhappy can someone help me get started?

    I need help getting started with this program. It uses the random generator and I don't have much experience with that. Can someone help me get start? Point me in the right direction and I'll do it and try it out and if i need more help i'll come back here and showyou what i have.

    Here's the program:

    Problem Statement:



    This problem will exercise both your modular programming skills, keeping track of lists and using the random number generators. We wish to produce 6 random numbers between the number 1 and 46. The program must run until a command is given to halt execution. During each pass, the program will prompt the user to hit enter, upon hitting enter, the program will produce 6 exclusive random numbers between 1 and 46. They need not appear in order and there must be no duplicates.



    Below is a list of the function prototypes that can be used :



    void ClearLOTTO (void);

    int GetLOTTO (void);

    int DUPLICATE (int Curr_Num);

    void newline (int Num_Lines);



    Implementation Details:



    - You must use the function rand and srand to produce the random numbers.

    - The system time will be used as a seed.

    - Only integers between and including the numbers 1 to 46 must be used.

    - The program must run until a command is entered to halt the program.

    - The main routine only makes calls to user-defined functions except for a simple loop statement to control execution.

    Hint: You may use a global variable such as int Lotto[6];
    Example Output:
    ENTER C TO CONTINUE OR ANY OTHER CHARACTER TO STOP: C
    RUN NUMBER 1: 5 6 9 12 46 13
    ENTER C TO CONTINUE OR ANY OTHER CHARACTER TO STOP: C
    RUN NUMBER 2: 12 1 3 18 42 10
    ENTER C TO CONTINUE OR ANY OTHER CHARACTER TO STOP: H
    THANK YOU FOR PLAYING OUR GAME.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Stop spamming the board.
    Read the faq. Read the sticky notes.
    Do some work on your own first.

    No one is going to write your code. If anyone does, the rest of us will be sure and ridicule them to the point of tears. Have a nice day.

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

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    41

    sorry

    i won't use the boards again. i just want some help. i didnt want u to write it for me.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826

    Re: sorry

    Originally posted by jlmac2001
    i won't use the boards again. i just want some help. i didnt want u to write it for me.
    I didn't say don't use the boards. I said follow the board rules. You didn't say what you are having problems with. You didn't post your attempt at the work. You didn't do anything other than tell us what you need done. The boards don't work like that. Make an effort, point out what you're having problems with, and then ask for help. Just follow the board guidelines.

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

  5. #5
    Registered User
    Join Date
    Oct 2002
    Posts
    41

    i started it

    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>

    int lotto [6];
    int getNumber(void);
    int duplicate (int);
    void clearLotto(void);
    void newline(int);
    void srand (unsigned int seed);
    int getRandNumber (void);

    int main()

    {

    char get, gar;
    int num1, num2, test, variable, sign, num;
    int runnum=0;

    printf ("Do you want to play the Lotto (y or n)?");
    scanf ("%c", &get);
    scanf ("%c", &gar);

    int getRandNumber ();
    while(get == 'y' || get == 'Y'){
    printf("\nRun number = %d", ++runnum);
    clearLotto();

    for (num1 = 0; num1<6; num1++){
    num2 = getNumber();
    sign = duplicate (num2);

    while (sign == 1){
    num2= getNumber();
    sign= duplicate (num2);}
    lotto[num1} = num2;
    printf("\t%d", lotto[6]);}

    return 0;

    }

    printf ("Thank You For Playing Our Game.");



    return 0;


    int getRandom Number(void)
    {
    int randomNumber;
    unsigned int seed;

    seed = clock();
    srand(seed);

    randomNumber = ((rand() % 10) + 1);

    return randomNumber;
    }
    }

  6. #6
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Read this and then edit your post.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  7. #7
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    int getRandNumber ();
    while(get == 'y' || get == 'Y'){
    The bolded line is considered a prototype, not a function call. Remove the 'int' from that line.

    You don't need to prototype srand.
    You should only call srand one time, so call it in your main function.

    Beyond that, what specificly are you having trouble with?

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

  8. #8
    Registered User
    Join Date
    Oct 2002
    Posts
    41
    Okay, I change that but what else do i need to do? Don't i need function definitions for the other functions? I tried compiling it and I got an error saying that lotto wasn't a function. i don't know why it said that.

  9. #9
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Here's a brief rundown on functions:

    Every function needs to be defined. That means, it has to have a function body that (optionally, ideally) does something. Here is an example of a defined function:
    Code:
    void myfunction( void )
    {
        printf("This is my function.\n");
    }
    The function body is what is enclosed in the { } pair. You must define a funtion before you use it, or you must prototype it and then define it later.

    Here are two examples of what I'm talking about:
    Code:
    void myfunction( void ); /* a prototype */
    
    int main( void )
    {
        myfunction( ); /* call the function */
    
        return 0;
    }
    
    /* define the function */
    void myfunction( void )
    {
        printf("Function...\n");
    }
    Here, because we have prototyped the function before calling it, the main function can see it.

    Code:
    /* define the function */
    void myfunction( void )
    {
        printf("Function...\n");
    }
    
    int main( void )
    {
        myfunction( ); /* call the function */
    
        return 0;
    }
    Here, because the whole function is defined before the main function is defined, the main function can see it.

    For each function you call, it has to be defined some place. You cannot call a function that doesn't exist.

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

  10. #10
    Registered User
    Join Date
    Mar 2003
    Posts
    18
    Keep trying Jlmac, keep posting your updates!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help getting started..matrices
    By BobDole11 in forum C Programming
    Replies: 7
    Last Post: 11-15-2008, 09:51 PM
  2. Help getting started :(
    By blackocellaris in forum C Programming
    Replies: 4
    Last Post: 11-05-2006, 06:50 PM
  3. Getting started
    By panzeriti in forum Game Programming
    Replies: 3
    Last Post: 06-28-2003, 10:13 AM
  4. How to get started?
    By anoopks in forum Linux Programming
    Replies: 0
    Last Post: 01-14-2003, 03:48 AM
  5. Need help getting started
    By Unregistered in forum C++ Programming
    Replies: 4
    Last Post: 09-02-2001, 11:08 PM