1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
/*
Program to construct sentences due to random number
*/
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <string>
#include <ctime>
using namespace std;
//Function prototypes, Implemented at bottom!
void createSentence(int);
int randNum(int);
void printSentence(int);
int main()
{
int seed = 0;
cout<<"Enter the seed\n";// basicly this will force my randFunction to take a paramete!
cin>>seed;// user to enter seed for random number generator
printSentence(seed);
}
int randNum(int a)
{
srand(a);
return (rand()%5);
}
void createSentence(int b)
{
int count = 0;
const char* article[5] = {" the", " a ", " one ", " some ", " any "};
const char* noun[5] = {" boy", " girl ", " dog ", " town ", " car "};
const char* verb[5] = {" drove ", " jumped ", " ran ", " walked ", " skipped "};
const char* preposition[5] = {" to ", " from ", " over ", " under ", " on "};
char Sentence[80] = {}; //array to carry full sentence!
//first word should be from article
if(count ==0) {
count++;
strcat(Sentence, article[randNum(b)]);
}
//second word should be from noun
if(count == 1) {
count++;
strcat(Sentence, noun[randNum(b)]);
}
//third word should be from verb
if(count == 2) {
count++;
strcat(Sentence, verb[randNum(b)]);
}// Prgram works properly up to HERE!
//This last two bits of statements fire an error, i dont understand why!
//fourth word should be from prepostition
if(count == 3) {
count++;
strcat(Sentence, preposition[randNum(b)]);
}
//fifth word should be from article
if(count == 4) {
count++;
strcat(Sentence, article[randNum(b)]);
}
//sixth word should be from noun
if(count == 5) {
count++;
strcat(Sentence, noun[randNum(b)]);
}
cout<<Sentence;
}
void printSentence(int c)
{
createSentence(c); //call create sentence
}
|