Generate two random number and multiply

Discussion in 'C Programming' started by jjmillertime@hotmail.com, Mar 5, 2007.

  1. Guest

    I'm new so i apologize if this is in the wrong spot. I'm also new to
    programming in C and i've been searching for quite a while on how to
    create a program using C that will generate two random numbers,
    multiply them, and ask you for the result. It also needs to have four
    responses for both right and wrong answers and should print them
    randomly as well. The program should use at least 2 functions. Any
    help would be greatly appreciated.

    Thanks
     
    , Mar 5, 2007
    #1
    1. Advertising

  2. santosh Guest

    wrote:
    > I'm new so i apologize if this is in the wrong spot. I'm also new to
    > programming in C and i've been searching for quite a while on how to
    > create a program using C that will generate two random numbers,
    > multiply them, and ask you for the result. It also needs to have four
    > responses for both right and wrong answers and should print them
    > randomly as well. The program should use at least 2 functions. Any
    > help would be greatly appreciated.
    >
    > Thanks


    This seems like a homework question. Have you atleast made an attempt.
    Attempt a try at the problem and post the code here, however bad it
    is.

    Hint: To generate pseudo-random integer values, use the rand function.
    Before using it, it's recommended to invoke the srand function to
    "seed" the pseudo-random number generator. To learn how to use rand
    and srand, try looking at your implementation's documentation for the
    Standard library. If it's a Unix system, try typing 'man 3 rand' and
    'man 3 srand' at the command prompt.

    To select a string, from a collection randomly, you can use the same
    rand function to get a random number, trim it down to be within the
    bounds of your array of strings and use it to index into the array and
    extract a random string.

    Well, try your hand at it.
     
    santosh, Mar 5, 2007
    #2
    1. Advertising

  3. Daniel Rudy Guest

    At about the time of 3/5/2007 7:23 AM, stated
    the following:
    > I'm new so i apologize if this is in the wrong spot. I'm also new to
    > programming in C and i've been searching for quite a while on how to
    > create a program using C that will generate two random numbers,
    > multiply them, and ask you for the result. It also needs to have four
    > responses for both right and wrong answers and should print them
    > randomly as well. The program should use at least 2 functions. Any
    > help would be greatly appreciated.
    >
    > Thanks
    >


    Homework?

    Go take a look and rand(3) and srand(3). It's standard C.

    http://www.acm.uiuc.edu/webmonkeys/book/c_guide/

    --
    Daniel Rudy

    Email address has been base64 encoded to reduce spam
    Decode email address using b64decode or uudecode -m

    Why geeks like computers: look chat date touch grep make unzip
    strip view finger mount fcsk more fcsk yes spray umount sleep
     
    Daniel Rudy, Mar 5, 2007
    #3
  4. <> wrote in message
    > I'm new so i apologize if this is in the wrong spot. I'm also new to
    > programming in C and i've been searching for quite a while on how to
    > create a program using C that will generate two random numbers,
    > multiply them, and ask you for the result. It also needs to have four
    > responses for both right and wrong answers and should print them
    > randomly as well. The program should use at least 2 functions. Any
    > help would be greatly appreciated.
    >

    rand() will generate a random number between 0 and RAND_MAX.
    RAND_MAX is usually 32767, which is too high for arithmetic drill.

    So get a random number in the range 1 = 100 by taking modulus 100. There are
    more accurate ways of doing this, but this should be fine now.

    Unfortunately you program will generate exactly the same numbers on each
    run. So call srand() with the time from time() to seed the random number
    generator.

    Having got your random numbers, print them out with a message asking the
    user to multiply. Then call scanf() to input the result. Don't forget to
    check the return value of scanf() to make sure the user actually entered a
    number.

    Now you need to check whether the number is correct. If it is, call the
    random number generator again and print out a random "well done" message -
    you can use a switch - if not, print out a "wrong answer message".


    --
    Free games and programming goodies.
    http://www.personal.leeds.ac.uk/~bgy1mm
     
    Malcolm McLean, Mar 5, 2007
    #4
  5. Guest

    > rand() will generate arandomnumber between 0 and RAND_MAX.
    > RAND_MAX is usually 32767, which is too high for arithmetic drill.
    >
    > So get arandomnumber in the range 1 = 100 by taking modulus 100. There are
    > more accurate ways of doing this, but this should be fine now.
    >
    > Unfortunately you program will generate exactly the same numbers on each
    > run. So call srand() with the time from time() to seed therandomnumber
    > generator.
    >
    > Having got yourrandomnumbers, print them out with a message asking the
    > user tomultiply. Then call scanf() to input the result. Don't forget to
    > check the return value of scanf() to make sure the user actually entered a
    > number.
    >
    > Now you need to check whether the number is correct. If it is, call therandomnumber generator again and print out arandom"well done" message -
    > you can use a switch - if not, print out a "wrong answer message".
    >
    > --
    > Free games and programming goodies.http://www.personal.leeds.ac.uk/~bgy1mm

    this is what i have so far, don't laugh, i know it's horrible, but i
    wanted to know if i'm going in the right direction... i think i'm lost
    and confused


    #include <stdlib.h>
    #include <math.h>
    #include <time.h>
    #define num_val 1
    int randnum (int k);
    int product (void);
    #define num1 (randnum)*1
    #define num2 (randnum)+1

    int main (void)
    {
    int num1= (randnum),
    num2= ((randnum) +2);
    int value, right, wrong;

    srand (unsigned) time ();

    printf ("Type -1 to exit!/n");
    printf ("What is the product of %d and %d:/t", num1, num2);
    scanf ("%d", &value);
    if (value==-1)
    printf ("Thanks for Playing, Goodbye!");
    else (value == product)
    printf ("Correct!");
    else if (value!=product)
    printf ("Wrong!");
    }
    return (0);
    }
    int randNum (int k)
    {
    int ranNum;
    ranNum = 1 + (int) ( (float) k * rand() / ( RAND_MAX % 100 ) );
    return (ranNum);
    }
    int product (int j)
    {
    int prod;
    prod = num1 * num2;
    return (prod);
    }
     
    , Mar 6, 2007
    #5
  6. Guest

    On Mar 5, 1:46 pm, "Malcolm McLean" <> wrote:
    > <> wrote in message
    > > I'm new so i apologize if this is in the wrong spot. I'm also new to
    > > programming in C and i've been searching for quite a while on how to
    > > create a program using C that willgeneratetworandomnumbers,
    > > multiply them, and ask you for the result. It also needs to have four
    > > responses for both right and wrong answers and should print them
    > > randomly as well. The program should use at least 2 functions. Any
    > > help would be greatly appreciated.

    >
    > rand() willgeneratearandomnumber between 0 and RAND_MAX.
    > RAND_MAX is usually 32767, which is too high for arithmetic drill.
    >
    > So get arandomnumber in the range 1 = 100 by taking modulus 100. There are
    > more accurate ways of doing this, but this should be fine now.
    >
    > Unfortunately you program willgenerateexactly the same numbers on each
    > run. So call srand() with the time from time() to seed therandomnumber
    > generator.
    >
    > Having got yourrandomnumbers, print them out with a message asking the
    > user to multiply. Then call scanf() to input the result. Don't forget to
    > check the return value of scanf() to make sure the user actually entered a
    > number.
    >
    > Now you need to check whether the number is correct. If it is, call therandomnumber generator again and print out arandom"well done" message -
    > you can use a switch - if not, print out a "wrong answer message".
    >
    > --
    > Free games and programming goodies.http://www.personal.leeds.ac.uk/~bgy1mm


    ok this is what i have so far, don't laugh, i know it's probably
    horrible, but if anyone could help with finishing it i would really
    appreciate it

    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    #include <time.h>
    #define num_val 1
    int randnum (int k);
    int product (int j);
    #define num1 ((randnum)*1)
    #define num2 ((randnum)+1)

    int main (void)
    {int value;

    srand (unsigned) time ();

    printf ("Type -1 to exit!/n");
    printf ("What is the product of %d and %d:/t", num1, num2);
    scanf ("%d", &value);
    if (value==-1)
    printf ("Thanks for Playing, Goodbye!");
    else (value == product)
    printf ("Correct!");
    else if (value!=product)
    printf ("Wrong!");
    }
    return (0);
    }
    int randNum (int k)
    {
    int ranNum;
    ranNum = 1 + (int) ( (float) k * rand() / ( RAND_MAX % 100 ) );
    return (ranNum);
    }
    int product (int j)
    {
    int prod;
    prod = num1 * num2;
    return (prod);
    }
     
    , Mar 6, 2007
    #6
  7. santosh Guest

    wrote:
    > On Mar 5, 1:46 pm, "Malcolm McLean" <> wrote:
    > > <> wrote in message
    > > > I'm new so i apologize if this is in the wrong spot. I'm also new to
    > > > programming in C and i've been searching for quite a while on how to
    > > > create a program using C that willgeneratetworandomnumbers,
    > > > multiply them, and ask you for the result. It also needs to have four
    > > > responses for both right and wrong answers and should print them
    > > > randomly as well. The program should use at least 2 functions. Any
    > > > help would be greatly appreciated.

    > >
    > > rand() willgeneratearandomnumber between 0 and RAND_MAX.
    > > RAND_MAX is usually 32767, which is too high for arithmetic drill.
    > >
    > > So get arandomnumber in the range 1 = 100 by taking modulus 100. There are
    > > more accurate ways of doing this, but this should be fine now.
    > >
    > > Unfortunately you program willgenerateexactly the same numbers on each
    > > run. So call srand() with the time from time() to seed therandomnumber
    > > generator.
    > >
    > > Having got yourrandomnumbers, print them out with a message asking the
    > > user to multiply. Then call scanf() to input the result. Don't forget to
    > > check the return value of scanf() to make sure the user actually entered a
    > > number.


    > ok this is what i have so far, don't laugh, i know it's probably
    > horrible, but if anyone could help with finishing it i would really
    > appreciate it
    >
    > #include <stdio.h>
    > #include <stdlib.h>
    > #include <math.h>
    > #include <time.h>
    > #define num_val 1
    > int randnum (int k);
    > int product (int j);
    > #define num1 ((randnum)*1)
    > #define num2 ((randnum)+1)


    Wrong invocation of function randnum. It expects an int parameter,
    according to your prototype above, but here you invoke it not only
    without a parameter, but also without the parenthesis. A function call
    must always have the accompanying parenthesis, even if there are no
    arguments.

    >
    > int main (void)
    > {int value;
    >
    > srand (unsigned) time ();


    srand((unsigned)time(NULL));

    > printf ("Type -1 to exit!/n");


    Newline is '\n', not '/n'. In fact all C escape sequences start with a
    '\', like '\t' for tab, '\a' for audible alert etc.

    > printf ("What is the product of %d and %d:/t", num1, num2);


    Likewise '\t' for tab.

    > scanf ("%d", &value);


    scanf is prone to failure. You should always check it's return value
    before proceeding.

    > if (value==-1)
    > printf ("Thanks for Playing, Goodbye!");
    > else (value == product)


    You mean an else if here, and an else below. Also, again you have to
    supply the parenthesis around a function call. product also expects an
    argument of type int.

    > printf ("Correct!");
    > else if (value!=product)
    > printf ("Wrong!");


    Also always include a newline character at the end of printf strings
    or alternatively call fflush(stdout) immediately afterwards, otherwise
    output may appear delayed due to buffering.

    > }
    > return (0);


    Parenthesis is redundant, but harmless.

    > }
    > int randNum (int k)


    This function is never called in your code. C is case sensitive.
    You've named this function randNum, but you invoke it as randnum,
    (which is itself incorrect), above. It'll lead to a linkage error,
    during compilation.

    > {
    > int ranNum;
    > ranNum = 1 + (int) ( (float) k * rand() / ( RAND_MAX % 100 ) );


    Huh? Why so much contortion. Just:

    return rand() % 100;

    should do.

    > return (ranNum);
    > }
    >
    > int product (int j)
    > {
    > int prod;
    > prod = num1 * num2;
    > return (prod);
    > }


    Why're you invoking num1 and num2 again? You should use the previous
    values. Each call to rand will return different values.
     
    santosh, Mar 6, 2007
    #7
  8. santosh Guest

    wrote:
    > On Mar 5, 1:46 pm, "Malcolm McLean" <> wrote:


    [ ... ]
    > > > create a program using C that willgeneratetworandomnumbers,
    > > > multiply them, and ask you for the result. It also needs to have four
    > > > responses for both right and wrong answers and should print them
    > > > randomly as well. The program should use at least 2 functions. Any
    > > > help would be greatly appreciated.

    [ ... ]

    Here's a short programme that may be similar to what you want:

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

    int main(void) {
    int n1, n2;
    long prd, guess;

    srand((unsigned int)time(NULL));

    n1 = 1 + (int)(100.0 * (rand() / (RAND_MAX + 1.0)));
    n2 = 1 + (int)(100.0 * (rand() / (RAND_MAX + 1.0)));
    prd = n1 * n2;

    printf("What is the product of %d and %d\?\n"
    "[Enter -1 to exit]\n", n1, n2);

    if(scanf("%ld", &guess) != 1) {
    puts("Incorrect input.");
    return EXIT_FAILURE;
    }
    else if(guess == -1) {
    puts("bye.");
    }
    else if(guess == prd) {
    puts("Correct!");
    }
    else {
    puts("Wrong guess.");
    }
    return 0;
    }
     
    santosh, Mar 6, 2007
    #8
  9. Guest

    On Mar 5, 10:44 pm, "santosh" <> wrote:
    > wrote:
    > > On Mar 5, 1:46 pm, "Malcolm McLean" <> wrote:
    > > > <> wrote in message
    > > > > I'm new so i apologize if this is in the wrong spot. I'm also new to
    > > > > programming inCand i've been searching for quite a while on how to
    > > > > create a programusingCthat willgeneratetworandomnumbers,
    > > > >multiplythem, and ask you for the result. It also needs to have four
    > > > > responses for both right and wrong answers and should print them
    > > > > randomly as well. The program should use at least 2 functions. Any
    > > > > help would be greatly appreciated.

    >
    > > > rand() willgeneratearandomnumber between 0 and RAND_MAX.
    > > > RAND_MAX is usually 32767, which is too high for arithmetic drill.

    >
    > > > So get arandomnumber in the range 1 = 100 by taking modulus 100. There are
    > > > more accurate ways of doing this, but this should be fine now.

    >
    > > > Unfortunately you program willgenerateexactly the same numbers on each
    > > > run. So call srand() with the time from time() to seed therandomnumber
    > > > generator.

    >
    > > > Having got yourrandomnumbers, print them out with a message asking the
    > > > user tomultiply. Then call scanf() to input the result. Don't forget to
    > > > check the return value of scanf() to make sure the user actually entered a
    > > > number.

    > > ok this is what i have so far, don't laugh, i know it's probably
    > > horrible, but if anyone could help with finishing it i would really
    > > appreciate it

    >
    > > #include <stdio.h>
    > > #include <stdlib.h>
    > > #include <math.h>
    > > #include <time.h>
    > > #define num_val 1
    > > int randnum (int k);
    > > int product (int j);
    > > #define num1 ((randnum)*1)
    > > #define num2 ((randnum)+1)

    >
    > Wrong invocation of function randnum. It expects an int parameter,
    > according to your prototype above, but here you invoke it not only
    > without a parameter, but also without the parenthesis. A function call
    > must always have the accompanying parenthesis, even if there are no
    > arguments.
    >
    >
    >
    > > int main (void)
    > > {int value;

    >
    > > srand (unsigned) time ();

    >
    > srand((unsigned)time(NULL));
    >
    > > printf ("Type -1 to exit!/n");

    >
    > Newline is '\n', not '/n'. In fact allCescape sequences start with a
    > '\', like '\t' for tab, '\a' for audible alert etc.
    >
    > > printf ("What is the product of %d and %d:/t", num1, num2);

    >
    > Likewise '\t' for tab.
    >
    > > scanf ("%d", &value);

    >
    > scanf is prone to failure. You should always check it's return value
    > before proceeding.
    >
    > > if (value==-1)
    > > printf ("Thanks for Playing, Goodbye!");
    > > else (value == product)

    >
    > You mean an else if here, and an else below. Also, again you have to
    > supply the parenthesis around a function call. product also expects an
    > argument of type int.
    >
    > > printf ("Correct!");
    > > else if (value!=product)
    > > printf ("Wrong!");

    >
    > Also always include a newline character at the end of printf strings
    > or alternatively call fflush(stdout) immediately afterwards, otherwise
    > output may appear delayed due to buffering.
    >
    > > }
    > > return (0);

    >
    > Parenthesis is redundant, but harmless.
    >
    > > }
    > > int randNum (int k)

    >
    > This function is never called in your code.Cis case sensitive.
    > You've named this function randNum, but you invoke it as randnum,
    > (which is itself incorrect), above. It'll lead to a linkage error,
    > during compilation.
    >
    > > {
    > > int ranNum;
    > > ranNum = 1 + (int) ( (float) k * rand() / ( RAND_MAX % 100 ) );

    >
    > Huh? Why so much contortion. Just:
    >
    > return rand() % 100;
    >
    > should do.
    >
    > > return (ranNum);
    > > }

    >
    > > int product (int j)
    > > {
    > > int prod;
    > > prod = num1 * num2;
    > > return (prod);
    > > }

    >
    > Why're you invoking num1 and num2 again? You should use the previous
    > values. Each call to rand will return different values.

    ok, i'm not sure if i fixed everything you were talking about, but i
    hope i did, thank you so much for your help, this is for homework and
    my teacher basically just tells us different parts of things but never
    really explains how to put anything together and its really irritating
    because i'm usually fairly computer literate


    int main (void)
    {int value,product;
    //set and seed rand
    srand ((unsigned) time (NULL));
    printf ("Type -1 to exit!\n");
    printf ("What is the product of %d and %d:\t", num1, num2);
    scanf ("%d", &value);
    product = ((num1) * (num2))
    //if value is -1, end program
    if (value!=-1)
    printf ("OK, Goodbuy!\n");
    else if ((value) == (product))
    printf ("Correct!\n");
    else ((value)!=(product))
    printf ("Wrong!\n");
    }
    return (0);
    }
    //first function
    int randnumber (int k)
    {
    int random;
    return rand() % 100;
    return (random);
    }
     
    , Mar 6, 2007
    #9
  10. Guest

    wow, thats so much cleaner, could you help me put another function
    into it so it will have 4 correct answers (eg "Thats right!") and 4
    wrong ("sorry try again") i know you probably have better things to
    do, but i have to hand it in in 30 minutes, and obviously i don't know
    what i'm doing
     
    , Mar 6, 2007
    #10
  11. santosh Guest

    wrote:
    > On Mar 5, 10:44 pm, "santosh" <> wrote:
    > > wrote:
    > > > On Mar 5, 1:46 pm, "Malcolm McLean" <> wrote:
    > > > > <> wrote in message


    [ ... ]

    > > > > > create a programusingCthat willgeneratetworandomnumbers,
    > > > > >multiplythem, and ask you for the result. It also needs to have four
    > > > > > responses for both right and wrong answers and should print them
    > > > > > randomly as well. The program should use at least 2 functions. Any
    > > > > > help would be greatly appreciated.


    [ ... ]

    > > > ok this is what i have so far, don't laugh, i know it's probably
    > > > horrible, but if anyone could help with finishing it i would really
    > > > appreciate it


    [ ... ]

    > ok, i'm not sure if i fixed everything you were talking about, but i
    > hope i did, thank you so much for your help, this is for homework and
    > my teacher basically just tells us different parts of things but never
    > really explains how to put anything together and its really irritating
    > because i'm usually fairly computer literate
    >
    >
    > int main (void)
    > {int value,product;
    > //set and seed rand
    > srand ((unsigned) time (NULL));
    > printf ("Type -1 to exit!\n");
    > printf ("What is the product of %d and %d:\t", num1, num2);


    Since you're not terminating your printf string with a newline, call
    fflush(stdout) after it.
    Additionally, I hope you've fixed your num1 and num2 macros.

    > scanf ("%d", &value);
    > product = ((num1) * (num2))


    Here's a mistake. Each invocation of the rand function returns
    different values. The two invocations above will not return the same
    values as the invocations within the printf statement earlier. So, in
    effect, you're computing a product to two different integers than what
    you presented to the user earlier.

    > //if value is -1, end program
    > if (value!=-1)


    if(value == -1)

    > printf ("OK, Goodbuy!\n");
    > else if ((value) == (product))
    > printf ("Correct!\n");
    > else ((value)!=(product))
    > printf ("Wrong!\n");
    > }
    > return (0);
    > }
    > //first function
    > int randnumber (int k)
    > {
    > int random;


    Don't use the identifier random. There're certain popular non-standard
    functions that use that name.

    > return rand() % 100;


    ITYM random = rand() % 100;

    But to get even better randomness do:

    random = 1 + (int)(100.0 * (rand() / (RAND_MAX + 1.0)));

    This uses the higher order bits of the value that rand returns, which
    are more random than the lower order bits.

    > return (random);


    Again the parenthesis aren't necessary.

    > }
     
    santosh, Mar 6, 2007
    #11
  12. santosh Guest

    wrote:
    > wow, thats so much cleaner, could you help me put another function
    > into it so it will have 4 correct answers (eg "Thats right!") and 4
    > wrong ("sorry try again") i know you probably have better things to
    > do, but i have to hand it in in 30 minutes, and obviously i don't know
    > what i'm doing


    Try this:

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

    #define CORRECT 1
    #define INCORRECT 0

    void print_rand_msg(const int msg_type);

    int main(void) {
    int n1, n2;
    long prd, guess;

    srand((unsigned int)time(NULL));

    n1 = 1 + (int)(100.0 * (rand() / (RAND_MAX + 1.0)));
    n2 = 1 + (int)(100.0 * (rand() / (RAND_MAX + 1.0)));
    prd = n1 * n2;

    printf("What is the product of %d and %d\?\n"
    "[Enter -1 to exit]\n", n1, n2);

    if(scanf("%ld", &guess) != 1) {
    puts("Incorrect input.");
    return EXIT_FAILURE;
    }
    else if(guess == -1) {
    puts("bye.");
    }
    else if(guess == prd) {
    print_rand_msg(CORRECT);
    }
    else {
    print_rand_msg(INCORRECT);
    }
    return 0;
    }

    void print_rand_msg(const int type) {
    char *correct_msgs[4] = { "Correct", "You're right!", "Perfect!",
    "You've hit the nail on the head!" };
    char *incorrect_msgs[4] = { "Wrong.", "Bad luck, try again",
    "Waaay of target.", "Not even close." };
    const int rndidx = 1 + (int)(4.0 * (rand() / (RAND_MAX + 1.0)));

    switch (type) {
    case CORRECT:
    puts(correct_msgs[rndidx]);
    break;
    case INCORRECT:
    puts(incorrect_msgs[rndidx]);
    break;
    default:
    puts("Wrong argument.");
    exit(EXIT_FAILURE);
    }
    return;
    }
     
    santosh, Mar 6, 2007
    #12
  13. Guest

    On Mar 5, 11:58 pm, "santosh" <> wrote:
    > wrote:
    > > wow, thats so much cleaner, could you help me put another function
    > > into it so it will have 4 correct answers (eg "Thats right!") and 4
    > > wrong ("sorry try again") i know you probably have better things to
    > > do, but i have to hand it in in 30 minutes, and obviously i don't know
    > > what i'm doing

    >
    > Try this:
    >
    > #include <stdio.h>
    > #include <stdlib.h>
    > #include <time.h>
    >
    > #define CORRECT 1
    > #define INCORRECT 0
    >
    > void print_rand_msg(const int msg_type);
    >
    > int main(void) {
    > int n1, n2;
    > long prd, guess;
    >
    > srand((unsigned int)time(NULL));
    >
    > n1 = 1 + (int)(100.0 * (rand() / (RAND_MAX + 1.0)));
    > n2 = 1 + (int)(100.0 * (rand() / (RAND_MAX + 1.0)));
    > prd = n1 * n2;
    >
    > printf("What is the product of %d and %d\?\n"
    > "[Enter -1 to exit]\n", n1, n2);
    >
    > if(scanf("%ld", &guess) != 1) {
    > puts("Incorrect input.");
    > return EXIT_FAILURE;
    > }
    > else if(guess == -1) {
    > puts("bye.");
    > }
    > else if(guess == prd) {
    > print_rand_msg(CORRECT);
    > }
    > else {
    > print_rand_msg(INCORRECT);
    > }
    > return 0;
    >
    > }
    >
    > void print_rand_msg(const int type) {
    > char *correct_msgs[4] = { "Correct", "You're right!", "Perfect!",
    > "You've hit the nail on the head!" };
    > char *incorrect_msgs[4] = { "Wrong.", "Bad luck, try again",
    > "Waaay of target.", "Not even close." };
    > const int rndidx = 1 + (int)(4.0 * (rand() / (RAND_MAX + 1.0)));
    >
    > switch (type) {
    > case CORRECT:
    > puts(correct_msgs[rndidx]);
    > break;
    > case INCORRECT:
    > puts(incorrect_msgs[rndidx]);
    > break;
    > default:
    > puts("Wrong argument.");
    > exit(EXIT_FAILURE);
    > }
    > return;
    >
    > }


    thanks so much for your help, i really appreciate it
     
    , Mar 6, 2007
    #13
  14. On 5 Mar 2007 22:05:31 -0800, in comp.lang.c ,
    wrote:

    >On Mar 5, 11:58 pm, "santosh" <> wrote:
    >> wrote:
    >>
    >> > do, but i have to hand it in in 30 minutes, and obviously i don't know
    >> > what i'm doing

    >>
    >> Try this:
    >>

    (snip example)
    >
    >thanks so much for your help, i really appreciate it


    Make sure you spend the time to understand it, so that when your
    teacher asks, you will be able to answer.
    --
    Mark McIntyre

    "Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are,
    by definition, not smart enough to debug it."
    --Brian Kernighan
     
    Mark McIntyre, Mar 6, 2007
    #14
  15. pete Guest

    Daniel Rudy wrote:
    >
    > At about the time of 3/5/2007 7:23 AM, stated
    > the following:
    > > I'm new so i apologize if this is in the wrong spot. I'm also new to
    > > programming in C and i've been searching for quite a while on how to
    > > create a program using C that will generate two random numbers,
    > > multiply them, and ask you for the result. It also needs to have four
    > > responses for both right and wrong answers and should print them
    > > randomly as well. The program should use at least 2 functions. Any
    > > help would be greatly appreciated.
    > >
    > > Thanks
    > >

    >
    > Homework?
    >
    > Go take a look and rand(3) and srand(3). It's standard C.
    >
    > http://www.acm.uiuc.edu/webmonkeys/book/c_guide/


    What is rand(3) supposed to mean?

    --
    pete
     
    pete, Mar 11, 2007
    #15
  16. CBFalconer Guest

    pete wrote:
    > Daniel Rudy wrote:
    >

    .... snip ...
    >>
    >> Go take a look and rand(3) and srand(3). It's standard C.
    >>
    >> http://www.acm.uiuc.edu/webmonkeys/book/c_guide/

    >
    > What is rand(3) supposed to mean?


    It means, on unixy systems, enter "man N topic". Here it would
    translate to "man 3 rand".

    --
    Chuck F (cbfalconer at maineline dot net)
    Available for consulting/temporary embedded and systems.
    <http://cbfalconer.home.att.net>



    --
    Posted via a free Usenet account from http://www.teranews.com
     
    CBFalconer, Mar 12, 2007
    #16
  17. santosh Guest

    pete wrote:
    > Daniel Rudy wrote:
    > >
    > > At about the time of 3/5/2007 7:23 AM, stated
    > > the following:
    > > > I'm new so i apologize if this is in the wrong spot. I'm also new to
    > > > programming in C and i've been searching for quite a while on how to
    > > > create a program using C that will generate two random numbers,
    > > > multiply them, and ask you for the result. It also needs to have four
    > > > responses for both right and wrong answers and should print them
    > > > randomly as well. The program should use at least 2 functions. Any
    > > > help would be greatly appreciated.
    > > >
    > > > Thanks
    > > >

    > >
    > > Homework?
    > >
    > > Go take a look and rand(3) and srand(3). It's standard C.
    > >
    > > http://www.acm.uiuc.edu/webmonkeys/book/c_guide/

    >
    > What is rand(3) supposed to mean?


    I think he meant to say man 3 rand.
     
    santosh, Mar 12, 2007
    #17
  18. pete <> writes:
    > Daniel Rudy wrote:

    [...]
    >> Go take a look and rand(3) and srand(3). It's standard C.
    >>
    >> http://www.acm.uiuc.edu/webmonkeys/book/c_guide/

    >
    > What is rand(3) supposed to mean?


    <OT>
    Under Unix, "rand(3)" refers to the man page for the rand function in
    section 3 of the manual; you can use "man 3 rand" or "man -s 3 rand"
    to read it.
    </OT>

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Mar 12, 2007
    #18
  19. Nelu Guest

    CBFalconer wrote:
    > pete wrote:
    >> Daniel Rudy wrote:
    >>

    > .... snip ...
    >>> Go take a look and rand(3) and srand(3). It's standard C.
    >>>
    >>> http://www.acm.uiuc.edu/webmonkeys/book/c_guide/

    >> What is rand(3) supposed to mean?

    >
    > It means, on unixy systems, enter "man N topic". Here it would
    > translate to "man 3 rand".
    >


    I think it was man -M 3 rand on Solaris 2.7 but the -M is no
    longer necessary on Linux systems.

    --
    Ioan - Ciprian Tandau
    tandau _at_ freeshell _dot_ org (hope it's not too late)
    (... and that it still works...)
     
    Nelu, Mar 12, 2007
    #19
  20. Nelu <> writes:
    > CBFalconer wrote:
    >> pete wrote:
    >>> Daniel Rudy wrote:
    >>>

    >> .... snip ...
    >>>> Go take a look and rand(3) and srand(3). It's standard C.
    >>>>
    >>>> http://www.acm.uiuc.edu/webmonkeys/book/c_guide/
    >>> What is rand(3) supposed to mean?

    >>
    >> It means, on unixy systems, enter "man N topic". Here it would
    >> translate to "man 3 rand".
    >>

    >
    > I think it was man -M 3 rand on Solaris 2.7 but the -M is no
    > longer necessary on Linux systems.


    <OT>
    Not quite. "man man" for details. (If you don't have the "man"
    command, then you don't need to know how it works.)
    </OT>

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Mar 12, 2007
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    11
    Views:
    643
    Neil Cerutti
    Nov 11, 2005
  2. globalrev
    Replies:
    4
    Views:
    823
    Gabriel Genellina
    Apr 20, 2008
  3. Sanchit
    Replies:
    20
    Views:
    18,888
    Richard Bos
    Oct 9, 2008
  4. Alex Untitled
    Replies:
    11
    Views:
    688
    Giampiero Zanchi
    Nov 16, 2009
  5. VK
    Replies:
    15
    Views:
    1,337
    Dr J R Stockton
    May 2, 2010
Loading...

Share This Page