The great struggle for random quotes!

This is a discussion on The great struggle for random quotes! within the Game Programming forums, part of the General Programming Boards category; Hey all. Inspired by a c++ forum question about quotes, I suddenly felt the erge to make a random quote ...

  1. #1
    mov.w #$1337,D0 Jeremy G's Avatar
    Join Date
    Nov 2001
    Posts
    704

    The great struggle for random quotes!

    Hey all. Inspired by a c++ forum question about quotes, I suddenly felt the erge to make a random quote generator.
    But not the typical random quote with predefined quotes that are randomly selected. No im talking about one with predefined words that combine them in random ways to make random quotes.

    I challenge every one to come up with there own fun version. or improve upon mine (not to hard there heh).

    Heres my code so far:
    Code:
    #include <iostream.h>
    #include <stdio.h>
    #include <windows.h>
    #include <string.h>
    #include <time.h>
    #include <stdlib.h>
    
    #define MAX_WORDS 10
    
    
    // prototypes
    void InitiatePartsOfSpeech();
    void CreateSentence();
    
    // global vars
    char *subject[4];
    char *verb[4];
    char *adverb[4];
    char *conjunction[5];
    char *adjective[4];
    char *structure[5];
    char sentence[1000] = ""; // profusely large :(
    
    
    int main()
    {
    	srand((unsigned)time(NULL));
    	InitiatePartsOfSpeech();
    
    	for( int i = 0; i < 10; i++ ) {
    		CreateSentence();	
    		sentence[1] = toupper(sentence[1]);
    		printf("%s.\n", sentence );
    		sprintf(sentence, "");
    	}
    
    	return 0;
    }
    
    void CreateSentence()
    {
    	bool hasSubject = false; // sentences must have one!
    	bool hasVerb = false; // sentences must have one!
    
    	int wordCount = 0;
    	
    	while( wordCount < 2 )
    		wordCount = rand()%MAX_WORDS;
    	
    	for( int i = 0; i < wordCount; i++ ) {
    		if( (i >= wordCount-2) && (!hasSubject) ) { sprintf(sentence, "%s %s", sentence, subject[rand()%4] ); hasSubject=true; };
    		if( (i >= wordCount-2) && (!hasVerb) ) { sprintf(sentence, "%s %s", sentence, verb[rand()%4] ); hasVerb=true; };
    				
    		int part = rand()%5;
    		if( part == 0 ) { sprintf(sentence, "%s %s", sentence, subject[rand()%4] ); hasSubject=true; };
    		if( part == 1 ) { sprintf(sentence, "%s %s", sentence, verb[rand()%4] ); hasVerb=true; };
    		if( part == 2 ) { sprintf(sentence, "%s %s", sentence, adverb[rand()%4] ); };
    		if( part == 3 ) { sprintf(sentence, "%s %s", sentence, adjective[rand()%4] ); };
    		if( part == 4 ) { sprintf(sentence, "%s %s", sentence, conjunction[rand()%5] ); };
    	}
    }
    
    void InitiatePartsOfSpeech()
    {
    	subject[0] = "war";
    	subject[1] = "life";
    	subject[2] = "death";
    	subject[3] = "peace";
    
    	verb[0] = "inflict";
    	verb[1] = "punish";
    	verb[2] = "ignore";
    	verb[3] = "govern";
    
    	adverb[0] = "unfortunatly";
    	adverb[1] = "easy";
    	adverb[2] = "dificult";
    	adverb[3] = "boldly";
    
    	adjective[0] = "bright";
    	adjective[1] = "dark";
    	adjective[2] = "many";
    	adjective[3] = "few";
    
    	conjunction[0] = "and";
    	conjunction[1] = "or";
    	conjunction[2] = "so";
    	conjunction[3] = "for";
    	conjunction[4] = "is";
    
    	structure[0] = "subject";
    	structure[1] = "verb";
    	structure[2] = "adverb";
    	structure[3] = "adjective";
    	structure[4] = "conjunction";
    }
    c++->visualc++->directx->opengl->c++;
    (it should be realized my posts are all in a light hearted manner. And should not be taken offense to.)

  2. #2
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    What's with the smileys in code postings?
    Il code one myself tommorow.

  3. #3
    mov.w #$1337,D0 Jeremy G's Avatar
    Join Date
    Nov 2001
    Posts
    704
    I have a habbit of commenting things i dont like, want to change, or reconsider with :( . I also forgot to disable smilies.
    c++->visualc++->directx->opengl->c++;
    (it should be realized my posts are all in a light hearted manner. And should not be taken offense to.)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stripping quotes from a string
    By -W0kk3L- in forum C Programming
    Replies: 3
    Last Post: 03-15-2006, 12:03 PM
  2. Google: How to make a great app no one can use
    By nickname_changed in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 03-10-2005, 06:31 AM
  3. Great Teacher..
    By vasanth in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 03-03-2003, 05:40 AM
  4. programming was great until c came along
    By Brian in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 10-04-2002, 07:37 PM
  5. Thought-provoking quotes
    By tim545666 in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 01-28-2002, 11:13 PM

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