random messages generator?

This is a discussion on random messages generator? within the C Programming forums, part of the General Programming Boards category; i would like to know how to generate random messages for a multiplication program. If the answer is correct the ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    22

    Exclamation random messages generator?

    i would like to know how to generate random messages for a multiplication program. If the answer is correct the program must generate one of the four correct responses. the same for an incorrect answer. i know that a program can generate random numbers but how I do to generate random messages? thanks..

  2. #2
    Registered User bljonk's Avatar
    Join Date
    Oct 2001
    Posts
    70

    pseudo are the best!

    1.create -two -2D arrays with four answers in it, one for correct answer -> with four answers and the a 2nd one for wrong answer -> with four answers in it.
    2.seed -> srand(time(NULL)) to prevent repeted paterns.
    3.use assert macro to verify the input as correct or wrong & select the correct array from where it peeks the a random message: 1+rand()%3.
    Ünicode¬>world = 10.0£

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    591
    Read the FAQ ,it's pretty good

  4. #4
    Registered User bljonk's Avatar
    Join Date
    Oct 2001
    Posts
    70

    ~codez

    #include <assert.h> // include only if u wanna use the assert macro. otherwise remove it.
    #include <stdlib.h>
    #include <time.h>

    char correct[3][]={{"true"},{"that's correct""},{"that's right!"},{"You just Hit the Jackpot!"},{"Perfercto!}};

    char wrong[3][]={{"false"},{"I'm sorry that's wrong!"},{"dumb ass!"},{"Wrong Answer!"},{"Tu eres un Burrito!!!"}};


    inline int multiply(int x,int y){
    return x * y;
    }

    int main(void){

    unsigned int x,y,answer,right,ping;

    srand(time(NULL));
    do{
    x = 1 + rand() % 12;
    y = 1 + rand() % 12;
    printf(" %d times %d is equal to: ",x,y);
    scanf("%d",answer);
    right = multiply(x,y);
    if(right == answer){
    ping = 1 + rand()%4
    puts(correct[ping][]);
    }else{
    ping = 1 + rand()%4
    puts(wrong[ping][]);
    }
    }while(answer != -1);
    return 0;
    }
    Ünicode¬>world = 10.0£

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How exactly does the random number generator work?
    By Finchie_88 in forum C++ Programming
    Replies: 6
    Last Post: 08-24-2007, 01:46 AM
  2. NAQ: Everything you never wanted to know about CPP
    By evildave in forum C Programming
    Replies: 21
    Last Post: 12-12-2005, 10:56 AM
  3. Testing Random Number Generator
    By Roaring_Tiger in forum C Programming
    Replies: 7
    Last Post: 08-12-2005, 01:48 AM
  4. Random Number Generator
    By Ikurik in forum C++ Programming
    Replies: 16
    Last Post: 08-17-2003, 08:34 PM
  5. Random number generator
    By Caze in forum C++ Programming
    Replies: 6
    Last Post: 12-03-2002, 08:10 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21