#include <iostream>
#include <ctime>
void PrintIntroduction(int Difficulty)
{
std::cout << "The riddle must perish for the world to survive! It is " << Difficulty;
std::cout << "\n Knocks of strength, come forth and I shall grant you a chance at it\n\n";
}
bool PlayGame(int Difficulty)
{
PrintIntroduction(Difficulty);
const int CodeA = rand() % Difficulty + Difficulty ;
const int CodeB = rand() % Difficulty + Difficulty ;
const int CodeC = rand() % Difficulty + Difficulty ;
const int CodeProduct = CodeA * CodeB * CodeC;
const int CodeSum = CodeA + CodeB + CodeC;
//Print CodeSum and CodeProduct to the terminal
std::cout <<"+ There are three numbers in the code\n";
std::cout <<"+ 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 players guess is correct
if (GuessSum == CodeSum && GuessProduct == CodeProduct)
{
std::cout << "\n Good work, you are now on level ";
return true;
}
else
{
std::cout << "\n Try again youngling";
return false;
}
}
int main()
{
srand(time(NULL));
int LevelDifficulty = 1;
int const MaxDifficulty = 5;
while (LevelDifficulty <= MaxDifficulty) // Loop until all levels completed
{
bool bLevelComplete = PlayGame(LevelDifficulty);
std::cin.clear();
std::cin.ignore();
if (bLevelComplete)
{
++LevelDifficulty;
}
}
std::cout << "You have won this game, the ancestors are proud";
return 0;
}```
This is what the terminal is saying:
- There are three numbers in the code
- The codes add-up to: 24842
- the codes multiply to give: 500801802
This code is working on my end, try recompiling.
1 Like
I tried both
cl triplex.cpp and cl triplex.cpp /EHsc but neither worked
Delete the triplex.exe and compile again.