-
Insult Generator Help?
Hi, my assignment involves writing a program that generates a random insult, made by randomly selecting a word in each of three lists. I know that I have to use pointers and character strings, but I was out of class for the past week and a half with pneumonia, so I'm kind of lost on how to do that and how to get it to print a random one from each of the lists. The final program should read "Thou *word from list 1* *word from list 2* *word from list 3* "
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
int main()
{
srand ( (unsigned)time( 0 ) );
char * list1[] = {"artless", "bardy", "beslubbering", "bootless",
"churlish", "cockered", "clouted", "craven", "currish", "dankish",
"dissembling", "droning", "errant", "fawning", "fobbing", "froward",
"frothy", "gleeking"};
char * list2[] = {"base-court", "bat-fowling", "beef-witted",
"beetle-headed", "boil-brained", "clapper-clawed", "clay-brained",
"common-kissing", "crook-pated", "dismal-greaming", "dizzy-eyed",
"doghearted", "earth-vexing", "dread-bolted", "elf-skinned",
"fat-kidneyed", "fen-sucked", "flap-mouthed"};
char * list3[] = {"apple-john", "baggage", "barnacle", "bladder",
"boar-pig", "bugbear", "bum-bailey", "canker-blossom", "clack-dish",
"clotpole", "coxcomb", "codpiece", "death-token", "dewberry",
"flap-dragon", "flax-wench", "flirt-gill", "foot-licker", "measle"};
printf("Thou %s, %s, %s\n", list1, list2, list3);
}
-
printf("Thou %s, %s, %s\n", list1[0], list2[8], list3[5]);
This will print the 1st, 7th and 4th insult from the list. Now you need three variables to replace the three constant numbers and you need to assign random numbers to those variables before printing.
-
Awesome, got it. Thanks so much!
-
One more quick question. I have to make it so at the end it asks if the user would like to try again, and then loop the program if they do. Right now I'm using a goto function, but I know that's shunned upon, but for whatever reason, I can't get it to work with an if or while loop.
This is what I have now
Code:
printf("Have you had enough? (y/n)\n");
scanf("%c", &ans);
if (ans == 'n' || ans == 'N')
{
goto rerun;
}