Help with Posting Code

I was going to post my code, but I can’t see how to format it properly :frowning:

Using 3 * ', as it says in this post:

Rob26d
Code is frequently shared on the GameDev.tv forum often by members of the community seeking an answer to a problem, or by members providing a solution to a problem. Providing consistent, easy to read code makes it easier for the person you are trying to help, or, for the people you are seeking help from.

Code formatting is essential for readability, please consider your community and take an extra moment to format your code in your post.

Applying code formatting;

On a new line, enter three ` characters

On the next line, paste / start writing your code

On a new line after your code, enter three ` characters

But the formatting is all over the place :frowning:

How do I do this (seemingly) simple task?

Cheers
(Incidentally - I did manage to get it into a nice box once - like the above text, but it had " >" in front of each line, which was a bit off-putting)

1 Like

```
int main()
{
return 0;
}
```

int main()
{
    return 0;
}

‘’’
#include
#include
#include “FBullCowGame.h”

// 2.49

using FText = std::string;
using int32 = int;

void PrintIntro();
int32 AskForDifficulty();//TODO change word length (and tries)
void PlayGame();
bool AskToPlayAgain();
FText GetValidGuess();
void PrintGameSummary();

// Instantiate a new game
FBullCowGame BCGame;

// entry Point of App
int main()
{
bool bPlayAgain = false;

do
{
	PrintIntro();
	PlayGame();
	PrintGameSummary();
	bPlayAgain = AskToPlayAgain();
}
while (bPlayAgain);

std::cout << std::endl;
return 0;	// Exit App

}

//Output Welcome & Rules
void PrintIntro()
{

std::cout << "\n\nWelcome to Bulls and Cows. A fun word game.\n";
std::cout << std::endl;
std::cout << "An Isogram is a word (or phrase) with no repeated letters.\n\n";
std::cout << "                   {                               \n";
std::cout << "       ~~~~~~~~~~^~ )        ( ~^~~~~~~~~~~        \n";
std::cout << "      /            O           O           \\      \n";
std::cout << "      |   BULL       @       C     COW     |       \n";
std::cout << "     (              (          )            )      \n";
std::cout << "       ~~~,~~~~~~~~             ~~~~~~~~~~~~ \\    \n";
std::cout << "      |           |            |            | \\   \n";
std::cout << "      /           /            \\            \\    \n";
std::cout << "      >           >            <            <      \n";
std::cout << "                                                   \n";
std::cout << "      A Bull is the              A Cow is a        \n";
std::cout << "   right letter in the       right letter in the   \n";
std::cout << "      right place               wrong place        \n";
std::cout << "                                                   \n";

/*std::cout << "Can you guess the " << BCGame.GetHiddenWordLength();
std::cout << " letter isogram I am thinking of? ";
std::cout << "(You have " << BCGame.GetMaxTries() << " tries)\n";
*/	//TODO Move this somewhere

return;

}

int32 AskForDifficulty()
{
int32 Level = 0;

std::cout << "The Difficulty Level will determine how many letters\n";
std::cout << "are in the hidden word, and how many guesses you get\n\n";
std::cout << "What Difficulty would you like (1 - 4)? ";
FText Input = "";
do
{
	std::getline(std::cin, Input);
	if (!isdigit(Input[0]) || (Input.length() != 1) )
	{
		std::cout << "Only a single digit please ";
	}
	else if (std::stoi(Input) < 1 || std::stoi(Input) > 4)
	{
		std::cout << "between 1 & 4 please ";
	}
	else
	{
		Level = std::stoi(Input);
	}
} while (Level < 1 || Level > 4);
return Level;

}

//Loop for number of tries
void PlayGame()
{
int32 Difficulty = AskForDifficulty();
BCGame.Reset(Difficulty);

int32 MaxTries = BCGame.GetMaxTries();

//	loop asking for guesses while game is NOT won
// and there are still tries available

while( !BCGame.IsGameWon() && BCGame.GetCurrentTry()<= MaxTries)
{
	FText Guess = GetValidGuess();

	//	Submit Valid guess to the game and get counts
	FBullCowCount BullCowCount = BCGame.SubmitValidGuess(Guess);
	
	// Print number of bulls and cows
	std::cout << "Bulls = " << BullCowCount.Bulls;
	std::cout << ". Cows = " << BullCowCount.Cows << std::endl;
}
return;

}

// Get guess from player and loop until it is valid (isogram, right length etc.)
FText GetValidGuess()
{
FText Guess = “”;
EGuessStatus Status = EGuessStatus::Invalid_Status;
do
{
int32 CurrentTry = BCGame.GetCurrentTry();
std::cout << "\nTry " << CurrentTry << "( / " << BCGame.GetMaxTries() << "). Enter your Guess: ";
std::getline(std::cin, Guess);
Status = BCGame.CheckGuessValidity(Guess);
switch (Status)
{
case EGuessStatus::Not_All_Letters:
std::cout << “Guess must not contain any numbers or special characters\n”;
std::cout << “Please Enter a word\n”;
break;
case EGuessStatus::Not_Lowercase:
std::cout << “Guess must be in Lower Case\n”;
std::cout << “Please Enter a word\n”;
break;
case EGuessStatus::Not_Isogram:
std::cout << “Guess must be an isogram\n”;
std::cout << “Please Enter a word\n”;
break;
case EGuessStatus::Wrong_Length:
std::cout << “Guess must contain " << BCGame.GetHiddenWordLength() << " letters\n”;
std::cout << “Please Enter a " << BCGame.GetHiddenWordLength() << " letter word\n”;
break;
default:
break;
}
} while (Status != EGuessStatus::OK);
return Guess;
}

// How did Player do?
void PrintGameSummary()
{
if (BCGame.IsGameWon())
{
std::cout << “** YOU WON!! ** \n”;
}
else
{
std::cout << “Better Luck Next time :-(\n”;
}
}

// Has the player had enough?
bool AskToPlayAgain()
{
std::cout << "\nDo you want to play again (y / n)? ";
FText Response = “”;
std::getline(std::cin, Response);
return ((Response[0] == ‘y’) || (Response[0] == ‘Y’));

}
’’'
aaarrrggghhh

back ticks ` not apostrophes ’

#include <iostream>
#include <string>
#include "FBullCowGame.h"

// 2.49
 

using FText = std::string;
using int32 = int;

void PrintIntro();
int32 AskForDifficulty();//TODO change word length (and tries)
void PlayGame();
bool AskToPlayAgain();
FText GetValidGuess();
void PrintGameSummary();


// Instantiate a new game
FBullCowGame BCGame;	

// entry Point of App
int main() 
{
	bool bPlayAgain = false;

	do
	{
		PrintIntro();
		PlayGame();
		PrintGameSummary();
		bPlayAgain = AskToPlayAgain();
	}
	while (bPlayAgain);
	
	std::cout << std::endl;
	return 0;	// Exit App
}

//Output Welcome & Rules
void PrintIntro() 
{

	std::cout << "\n\nWelcome to Bulls and Cows. A fun word game.\n";
	std::cout << std::endl;
	std::cout << "An Isogram is a word (or phrase) with no repeated letters.\n\n";
	std::cout << "                   {                               \n";
	std::cout << "       ~~~~~~~~~~^~ )        ( ~^~~~~~~~~~~        \n";
	std::cout << "      /            O           O           \\      \n";
	std::cout << "      |   BULL       @       C     COW     |       \n";
	std::cout << "     (              (          )            )      \n";
	std::cout << "       ~~~,~~~~~~~~             ~~~~~~~~~~~~ \\    \n";
	std::cout << "      |           |            |            | \\   \n";
	std::cout << "      /           /            \\            \\    \n";
	std::cout << "      >           >            <            <      \n";
	std::cout << "                                                   \n";
	std::cout << "      A Bull is the              A Cow is a        \n";
	std::cout << "   right letter in the       right letter in the   \n";
	std::cout << "      right place               wrong place        \n";
	std::cout << "                                                   \n";
	
	/*std::cout << "Can you guess the " << BCGame.GetHiddenWordLength();
	std::cout << " letter isogram I am thinking of? ";
	std::cout << "(You have " << BCGame.GetMaxTries() << " tries)\n";
	*/	//TODO Move this somewhere

	return;
}

int32 AskForDifficulty()
{
	int32 Level = 0;

	std::cout << "The Difficulty Level will determine how many letters\n";
	std::cout << "are in the hidden word, and how many guesses you get\n\n";
	std::cout << "What Difficulty would you like (1 - 4)? ";
	FText Input = "";
	do
	{
		std::getline(std::cin, Input);
		if (!isdigit(Input[0]) || (Input.length() != 1) )
		{
			std::cout << "Only a single digit please ";
		}
		else if (std::stoi(Input) < 1 || std::stoi(Input) > 4)
		{
			std::cout << "between 1 & 4 please ";
		}
		else
		{
			Level = std::stoi(Input);
		}
	} while (Level < 1 || Level > 4);
	return Level;
}

//Loop for number of tries
void PlayGame()
{ 
	int32 Difficulty = AskForDifficulty();
	BCGame.Reset(Difficulty);

	int32 MaxTries = BCGame.GetMaxTries();
	
	//	loop asking for guesses while game is NOT won
	// and there are still tries available

	while( !BCGame.IsGameWon() && BCGame.GetCurrentTry()<= MaxTries)
	{
		FText Guess = GetValidGuess();

		//	Submit Valid guess to the game and get counts
		FBullCowCount BullCowCount = BCGame.SubmitValidGuess(Guess);
		
		// Print number of bulls and cows
		std::cout << "Bulls = " << BullCowCount.Bulls;
		std::cout << ". Cows = " << BullCowCount.Cows << std::endl;
	}
	return;
}

// Get guess from player and loop until it is valid (isogram, right length etc.)
FText GetValidGuess()
{
	FText Guess = "";
	EGuessStatus Status = EGuessStatus::Invalid_Status;
	do
	{
		int32 CurrentTry = BCGame.GetCurrentTry();
		std::cout << "\nTry " << CurrentTry << "( / " << BCGame.GetMaxTries() << "). Enter your Guess: ";
		std::getline(std::cin, Guess);
		Status = BCGame.CheckGuessValidity(Guess);
		switch (Status)
		{
		case EGuessStatus::Not_All_Letters:
			std::cout << "Guess must not contain any numbers or special characters\n";
			std::cout << "Please Enter a word\n";
			break;
		case EGuessStatus::Not_Lowercase:
			std::cout << "Guess must be in Lower Case\n";
			std::cout << "Please Enter a word\n";
			break;
		case EGuessStatus::Not_Isogram:
			std::cout << "Guess must be an isogram\n";
			std::cout << "Please Enter a word\n";
			break;
		case EGuessStatus::Wrong_Length:
			std::cout << "Guess must contain " << BCGame.GetHiddenWordLength() << " letters\n";
			std::cout << "Please Enter a " << BCGame.GetHiddenWordLength() << " letter word\n";
			break;
		default:
			break;
		}
	} while (Status != EGuessStatus::OK);
	return Guess;
}

// How did Player do?
void PrintGameSummary()
{
	if (BCGame.IsGameWon())
	{
		std::cout << "** YOU WON!! ** \n";
	}
	else
	{
		std::cout << "Better Luck Next time :-(\n";
	}
}

// Has the player had enough?
bool AskToPlayAgain()
{
	std::cout << "\nDo you want to play again (y / n)? ";
	FText Response = "";
	std::getline(std::cin, Response);
	return ((Response[0] == 'y') || (Response[0] == 'Y'));

}

Heh - Thanks so much - I tried everything but :slight_smile: