There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 bios blue screen boot bsod computer connection cpu crash css dell desktop dma driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware hijackthis hjt install internet internet explorer itunes keyboard laptop macro malware monitor motherboard network networking outlook outlook 2003 outlook 2007 outlook express pio problem problems router seo server slow sound sp3 spyware trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
Help with my program!!


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
Rhino24's Avatar
Member with 41 posts.
 
Join Date: Feb 2008
Experience: Beginner
16-Apr-2008, 03:08 PM #1
Help with my program!!
Can somebody finish this off for me I am trying to write a program that produces random limericks and I am about to give up on this one. Can somebody Please, Please Help me out!
Thanks
Code:
[inlinecode]
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>


int main(){

	char *sentence1[]={"There Once was a Man called Reg"};
	char *sentence2[]={"Who Went with a Girl in a Hedge"};
	char *sentence3[]={"Along came his wife"};
	char *sentence4[]={"With a big Carving Knife"};
	char *sentence5[]= {"And cut off his meat and two veg"};
    char *sentence[] = {","};
	int i=0;

	for (i=1; i<=20; i++){
		strcat (sentence, sentence1[rand()%5]);
		strcat (sentence, sentence," ");

		strcat (sentence, sentence2[rand()%5]);
		strcat (sentence, " ");

		strcat (sentence, sentence3[rand()%5]);
		strcat (sentence,  " ");

		strcat (sentence, sentence4[rand()%5]);
		strcat (sentence, " ");

		strcat (sentence,  sentence5[rand()%5]);
		strcat (sentence, " ");
		
				
		
		printf("%s\n", &sentence[1]);}

		return 0;

}
[/inlinecode]
tritonfx's Avatar
Junior Member with 24 posts.
 
Join Date: Jan 2008
16-Apr-2008, 06:54 PM #2
My C++ is a little rusty and don't have a compiler w/ me but maybe, just maybe, this'll help.
My code might stink but it's been a while.
Code:
char sentence[1000] = "  "; // Indentation for sentence
char *opening[] = {"There once was a boy", "There lived an old man", "Alone was the woman"};
char *sentences[] = { "who bit off his shoe", "who flew to the moon", "that ate his last pie", "he came from the land" };

strcat(sentence, opening[rand()% 3];
for(int i = 0; i < NUMBER_OF_LINES; i++){
    strcat(sentence, sentences[rand()% 3];
    strcat(sentence, ", ");
}
strcat(sentence, ".");
Obviously I didnt put any error checking/out of bounds things.
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 01:27 PM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.