470,636 Members | 1,420 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,636 developers. It's quick & easy.

help with a program

hi,
I'm trying to write a program in wich I would generate 20 sentences out of
4 arrays(articles,nouns,preposition,verb).I have to select an item at random
from each array and concatetane each one of those selections to form a sentence,
I have to form 20 sentences. I have no compiling errors but when I execute
the program is giving an execption. This is the code I have


// program uses randon number generation to create sentences

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

#include<ctype.h>
#include<string.h>

const int row= 20;
const int column= 80;
void touppercase(char *string);
void concatenate(char *array[][column],int element,char *string[],int size);


int main()
{

srand(time(NULL));

char *array[row][column] = {" "};
int position= 0,
counter= 1;
char *article[5]= {"the","a","one","some","any"};
char *noun[5]= {"boy","girl","dog","town","car"};
char *verb[5]= {"drove","jumped","ran","walked","skipped"};
char *preposition[5]= {"to","from","over","under","on"};

do
{


if(counter == 20)
touppercase(article[position]);

concatenate(array,counter,article,row);

concatenate(array,counter,noun,row);

concatenate(array,counter,verb,row);


concatenate(array,counter,preposition,row);


}while(counter < 21);
for(int i =0;i<20;i++)
for(int j =0;j<20;j++)
cout<<array[i][j]<<endl;

return 0;
}

void touppercase(char *string)
{
int i =0;
while((*string != '\0') && (i != 1))
{
*string = toupper(*string);
++i;
}
}
void concatenate(char *array[][column],int element, char *string[],int size)
{
int position = 0;
position = (1 + rand() % 5);
strcpy(array[element][column],string[position]);
}

any suggetion on this will be greatly appriciated.
Thanks,
Oct 29 '06 #1
2 1505
can any one help please..
Oct 30 '06 #2
I need help please...
Oct 30 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by PHPkemon | last post: by
6 posts views Thread by wukexin | last post: by
7 posts views Thread by tyler_durden | last post: by
6 posts views Thread by HelpME | last post: by
1 post views Thread by Korara | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.