# How can I make that every level of TripleX has different messages?

In the TripleX part of the course we did this hacker game with randomized numbers, but after I ended it I thought how I could change the messages that there are at the start of the level, and make that every level has its own set of messages…
but I don’t really know how to do it, so can I get some help understand how I can do it?

Here is how I made TripleX, in case it is needed.

``````#include <iostream>

#include <ctime>

void PrintIntroduction (int Difficulty)

{

std::cout << "\n\nStop right there adventurer, I'm the protector of the treasure of the level " << Difficulty;

std::cout << "\nif you want to take what is inside it, you must give me the correct code, and pass the test...\n\n";

}

bool PlayGame (int Difficulty)

{

PrintIntroduction(Difficulty);

const int CodeA = rand() % (Difficulty * 2) + 1;

const int CodeB = rand() % (Difficulty * 2) + 1;

const int CodeC = rand() % (Difficulty * 2) + 1;

const int CodeSum = CodeA + CodeB + CodeC;

const int CodeProd = CodeA * CodeB * CodeC;

std::cout << "1. the code has a total of 3 numbers.\n";

std::cout << "2. the sum of the number inside the code is: " << CodeSum << std::endl;

std::cout << "3. the product between the 3 numbers is: " << CodeProd << std::endl;

int GuessA, GuessB, GuessC;

std::cin >> GuessA >> GuessB >> GuessC;

int GuessSum = GuessA + GuessB + GuessC;

int GuessProd = GuessA * GuessB * GuessC;

//Check if player is wrong

if (GuessSum == CodeSum && GuessProd == CodeProd)

{

std::cout << "You are worthy of the treasure random adveturer!\n";

return true;

} else {

std::cout << "You really believe that is the right answer!? Go away adventurer!\n";

return false;

}

}

int main ()

{

srand(time(NULL));

int LevelDifficulty = 1;

const int MaxLevel = 5;

while (LevelDifficulty <= MaxLevel)

{

bool BLevelComplete = PlayGame(LevelDifficulty);

std::cin.clear();

std::cin.ignore();

if (BLevelComplete) {

++LevelDifficulty;

}

}

std::cout << "\nYou're the best adventurer of all the world, great job!";

return 0;

}

``````

One way you could do this is by using the Difficulty variable to determine what level the player is on and what message should be displayed.

After you declare your constants in the PlayGame function, you could write something like this:

``````if (Difficulty == 1)
{
std::cout << "Message for 1st level.";
}

if (Difficulty == 2)
{
std::cout << "Message for 2nd level.";
}
``````

Hope this helps!

1 Like

Oh, I see, I’ll try to do it and see what happen, thank for the help!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.