#include <iostream>
using namespace std;
//declare base variables
string UserResponse;
bool bLevelComplete;
int Level = 1;
int CodeA = 1;
int CodeB = 2;
int CodeC = 3;
int CodeSum = CodeA+CodeB+CodeC;
int CodeProduct = CodeA*CodeB*CodeC;
int PlayerGuess1, PlayerGuess2, PlayerGuess3;
int GuessSum;
int GuessProduct;
//define base Functions
void PrintIntro()
{
cout <<"\n Welcome to my game!\n Solve The Codes To Move On...\n Good Luck!\n";
}
void AskQuestion()
{
cout << "\n -There are three numbers in the code...\n -The numbers add up to " << CodeSum << "...\n -The numbers multiply out to " << CodeProduct << "...\n\n Input Code (separate values with spaces): ";
cin >> PlayerGuess1 >> PlayerGuess2 >> PlayerGuess3;
cout << "\n You entered: " << PlayerGuess1 << ", " << PlayerGuess2 << ", " << PlayerGuess3 << ".\n";
GuessSum = PlayerGuess1+PlayerGuess2+PlayerGuess3;
GuessProduct = PlayerGuess1*PlayerGuess2*PlayerGuess3;
}
void YouWin()
{
cout << "\n You Win! Congratulations and thank you so much for playing!\n Feel free to reach out to @the_L1ghtBr1nger on telegram if you're interested in collaborating in the future!\n\n Good Luck With Your Projects!\n";
}
bool PlayGame()
{
if (Level == 10)
{
YouWin();
return false;
}
//Output current level
cout << "\n Level: " << Level << endl;
AskQuestion();
if(GuessSum == CodeSum && GuessProduct == CodeProduct)
{
cout << " Good Job!\n";
Level = Level+1;
return true;
}
else
{
cout << " Sorry wrong input\n Try Again? (Y/n) ";
cin >> UserResponse;
cout << endl;
if (UserResponse == "n")
{
return false;
}
else
{
Level = 1;
return true;
}
}
}
//TripleX game: Ask user to find 3 digit code based on provided sum and product of numbers within code.
int main()
{
PrintIntro();
while(true)
{
bLevelComplete = PlayGame();
cin.clear(); //Clears error from non-int input
cin.ignore(); //Discards buffer
}
return 0;
}
I just recently restarted as my last program diverted too heavily from the course it became too difficult to troubleshoot, worried I’ve diverted here but can’t figure out why this isn’t working