Ok, now I'm feeling dumb and all, but I need help on how to a print a secret random code if I said yes on cheat, and I should not let it be printed if the answer on the cheat is no(but it should still be stored in a value for later use). so I'm just curious should I make the function on cheat "int cheat" instead of "void cheat"? cause I don't know how to give the value of cheat to main so that it can answer the question to print the secret random code. And I need help finding out in what variable the secret code is stored in so I can print it on int main() P.S. I need it as functions.

void random()
{
	int i, j;
	char* animals[size] = {"ant", "bear", "cat", "dog", "emu", "goat", "lizard", "monkey", "parrot", "rabbit", "snake", "tiger"};
	char* chosen[4] = {"", "", "", ""};
	srand(time(NULL));

	for( i = 0; i < 4; i++ )
	{
		chosen[i] = animals[rand()%12];
		for( j = 0; j < 4; j++ )
			if( strcmp(chosen[i], chosen[j]) == 0 && j != i ) 
			{
				i--;
				break;
			}
	}
	for( i = 0; i < 4; i++ )
	{
		printf("%c", chosen[i][0]);
	}
	printf("\n");
}
void cheat()
{
    char cheat;
    printf("need cheats? <y-Yes,n-No>");
    scanf(" %c",&cheat);
    while(cheat != 'y' && cheat != 'n')
    {                 
    scanf("%c",&cheat);
    }
}
    
    
int main()
{
    cheat(cheat);
    random();
    system("pause");
}

this is my code so far. Hope you can help I will appreciate any kind of help given.

Recommended Answers

All 6 Replies

A very convoluted confusing question.

Ok, now I'm feeling dumb and all, but I need help on how to a print a secret random code if I said yes on cheat, and I should not let it be printed if the answer on the cheat is no(but it should still be stored in a value for later use).

You did an input and accepted a value. if you need it later, keep it.

so I'm just curious should I make the function on cheat "int cheat" instead of "void cheat"?

Do you want to return the value your got from the user? If so, yes.

cause I don't know how to give the value of cheat to main so that it can answer the question to print the secret random code.

Return it. Reread the chapter on functions.

And I need help finding out in what variable the secret code is stored in so I can print it on int main() P.S. I need it as functions.

It's your program -- put it in whatever variable you want.

Wow Thanks! can you give me the link on functions pls :)

Wow Thanks! can you give me the link on functions pls :)

Why? Can't you look in your book? Don't you know how to use Google? Can't you think for yourself?

Sorry... Just asking for some suggestions cause I can't seem to find tutorials that works well for me :|

Here are a lot of links about functions. If there's something you don't understand, ask a specific question. Be sure you give enough information that we know what you are having trouble with. Why does the info not make sense is something good to add.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.