Hey I have just finished creating the Triplex game with C++ and I’m loving the course so far! I’ve had no problems until the very end when I use the codes #include & srand(time(NULL));
When I try to run Triplex on the terminal I get the error “The system cannot execute the specified program.” and then my anti virus pops up saying Trojan:Win32/Wacatac.B!ml which is obviously false. When I check the location it is indeed Triplex.exe so what is up?
It must be something to do with the complier and the clock on the computer or something? Here’s my code, thank you.
#include <iostream>
#include <ctime>
void PrintIntroduction(int Difficulty)
{
std::cout << "\n\nYou're a secret agent breaking into a level " << Difficulty;
std::cout << " secure server room...\nYou need to enter the correct codes to continue...\n\n";
}
bool PlayGame(int Difficulty)
{
PrintIntroduction(Difficulty);
const int CodeA = rand() % Difficulty + Difficulty + Difficulty;
const int CodeB = rand() % Difficulty + Difficulty + Difficulty;
const int CodeC = rand() % Difficulty + Difficulty + Difficulty;
const int CodeSum = CodeA + CodeB + CodeC;
const int CodeProduct = CodeA * CodeB * CodeC;
// Print CodeSum and CodeProduct to the terminal
std::cout << "+There are 3 numbers in the code";
std::cout << "\n+The codes add-up to: " << CodeSum;
std::cout << "\n+The codes multiply to give: " << CodeProduct << std::endl;
// Store player guess
int GuessA, GuessB, GuessC;
std::cin >> GuessA >> GuessB >> GuessC;
int GuessSum = GuessA + GuessB + GuessC;
int GuessProduct = GuessA * GuessB * GuessC;
// Check if the players guess is correct
if (GuessSum == CodeSum && GuessProduct == CodeProduct)
{
std::cout << "\n*** Well done agent! You have extracted the file! Keep going ***";
return true;
}
else
{
std::cout << "\n*** You have entered the incorrect code! Careful agent! Try again! ***";
return false;
}
}
int main()
{
srand(time(NULL)); // Creates new random sequence based on time of day
int LevelDifficulty = 1;
const int MaxDifficulty = 10;
while (LevelDifficulty <= MaxDifficulty) // Loop game until all levels are completed
{
bool bLevelComplete = PlayGame(LevelDifficulty);
std::cin.clear(); // Clears any errors
std::cin.ignore(); // Discards the buffer
if (bLevelComplete)
{
++LevelDifficulty;
}
}
std::cout << "\n*** Great work agent! You got all the files! Now get out of there! ***\n";
return 0;
}