// xxx_NumberGame.cpp : This file contains the ‘main’ function. Program execution begins and ends there.
//
#include
void PlayIntro(int Difficulty)
{
std::cout << "\nYou are secret agent, Breaking into the level " << Difficulty;
//We have used endl function to end the line. we can also use \n to get the same output but this seems more standard and correct
std::cout << “\nYou need to enter the correct codes to continue…”;
std::cout << std::endl;
}
bool PlayGame(int Difficulty)
{
PlayIntro(Difficulty);
int NumA = 4;
int NumB = 6;
int NumC = 7;
int CodeSum = NumA + NumB + NumC;
int CodeProd = NumA * NumB * NumC;
std::cout << "\n+There are three numbers in the code ";
std::cout << "\n+The numbers add upto " << CodeSum;
std::cout << "\n+Product of these three numbers is " << CodeProd;
std::cout << "\n";
std::cout << "\nGo ahead and enter the three numbers\n";
int GuessA, GuessB, GuessC;
std::cin >> GuessA >> GuessB >> GuessC;
int GuessSum;
int GuessProduct;
GuessSum = GuessA + GuessB + GuessC;
GuessProduct = GuessA * GuessB * GuessC;
if (GuessSum == CodeSum && GuessProduct == CodeProd)
{
std::cout << "\n******Correct Guess Genius!!!!! You are Adavancing to the next level!!*******";
return true;
}
else
{
std::cout << "\n!!!!OOPPPPSSS You are going to die#####";
return false;
}
}
int main()
{
int LevelDifficulty = 1;
int const MaxLevel = 3;
while (LevelDifficulty <= MaxLevel) //Loop Game untill all level gets completed
{
bool bLevelComplete = PlayGame(LevelDifficulty);
std::cout << std::endl;
PlayGame(LevelDifficulty);
std::cin.clear();
std::cin.ignore();
if (bLevelComplete)
{
++LevelDifficulty;
}
}
std::cout << "Congrats Agent You fucking won!!!";
return 0;
}
Can Someone please go through this code and explain me why do I have to enter correct code twice to advance to the next level!!! Please this is killing me. I am noob :((((((((((((((((((((