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";
}