#include <iostream>
void PrintIntroduction( int PasswordCodeSum, int PasswordCodeMultiplication, int Difficulty)
{
std::cout << "You are now a Treasure Hunter try to get the precious treasure" << std::endl;
std::cout << "To get the treasure you need to input the correct password for level " << Difficulty <<"\n\n";
std::cout << "There are 3 numbers in the password code" << std::endl;
std::cout << "The password codes add-up to: " << PasswordCodeSum << std::endl;
std::cout << "The password codes mutiply to give: " << PasswordCodeMultiplication << "\n\n";
}
bool PlayGame(int Difficulty)
{
int PasswordCodeA{ rand() }, PasswordCodeB{ rand() }, PasswordCodeC{ rand() };
int PasswordCodeSum{ PasswordCodeA + PasswordCodeB + PasswordCodeC };
int PasswordCodeMultiplication{ PasswordCodeA * PasswordCodeB * PasswordCodeC };
int GuessA{}, GuessB{}, GuessC{};
int GuessSum{}, GuessMultiplication{};
PrintIntroduction(PasswordCodeSum, PasswordCodeMultiplication, Difficulty);
std::cout << "Please enter your guess password codes: ";
std::cin >> GuessA;
std::cin >> GuessB;
std::cin >> GuessC;
GuessSum = GuessA + GuessB + GuessC;
GuessMultiplication = GuessA * GuessB * GuessC;
if (GuessSum == PasswordCodeSum && GuessMultiplication == PasswordCodeMultiplication)
{
std::cout << "Proceed to next level!" << std::endl;
return true;
}
else
{
std::cout << "Wrong answer please try it again!\n\n";
return false;
}
}
int main()
{
int LevelDifficulty{ 1 };
constexpr int MaxLevel{ 5 };
while (LevelDifficulty <= MaxLevel) // Loop
{
bool bLevelComplete{ PlayGame(LevelDifficulty) };
std::cin.clear(); // Clear any errors
std::cin.ignore(); // Discard the buffer
if (bLevelComplete)
{
++LevelDifficulty;
}
}
std::cout << "You have won an Acient Precious Treasure!" << std::endl;
return 0;
}
Sorry for long code