Hello,
I am Mohit and I am facing difficulty while I run my code, as windows defender pops up saying that it found a new threat and stop the code in the middle of running. I have added the screenshot and the code, please help me with this problem. Thank you
// #include is the preprocessor Directive
#include <iostream> //includes prepared library file
void PrintStory()
{
//printing welcome messages in the main body
std::cout << "\n\nHello?\n"; //Expression statement //Expression statement
std::cout << "Can you hear me??\n"; //Expression statement
std::cout << "Don't worry the line is secured\n";
std::cout << "If you can then say 0 if not then say 1\n";
int Ans = 0;
int PlayersAnswer;
std::cin >> PlayersAnswer;
if (PlayersAnswer == Ans)
{
std::cout << "Thank god!, I have been trying to connect to you from quiet a while\n";
}
else
{
std::cout << "It's not a proper time to joke, I am in a pretty dangerous situation\n";
std::cout << "So, STOP FOOLING AROUND!!!\n";
}
std::cout << "Listen, you need to help me \n";
std::cout << "I have been trapped in an undergroud facility by some goons working for Mr.S and they have been tortuering me since to get info about you\n";
std::cout << "Don't worry your location is secured\n";
std::cout << "-----------------------------------------------------------------------------------------------------------------\n";
std::cout << "ok here's the plan\n";
std::cout << "It feels like I am at 1st floor\n";
std::cout << "Each floor is under security servilance and will go under lockdown once there's a security breach, That's us\n";
std::cout << "And to unlock those floor, one by one we have to put all security clearance code made up off 3 digits\n";
std::cout << "Correct answer gets me one step floor to freedom\n";
std::cout << "Wrong answer, well we will both know when that happens\n";
std::cout << "Ok then, ARE YOU READY?????\n";
std::cout << "Here goes nothing.....\n";
std::cout << "-----------------ALL SECURITY PERSONELS ALERT THERES A SECURITY BREACH ON 108th FLOOR-----------------------------\n\n";
}
void PrintIntroduction(int Difficulty) //user function 1 with a parameter
{
std::cout << "\n\n++++REMEMBER++++\n\n";
std::cout << "This is level : " << Difficulty << std::endl << std::endl;
}
bool PlayGame(int Difficulty) //User function 2
{
//Prints the introduction stored in 1st user function
PrintIntroduction(Difficulty);
//Declaring 5 variables
//const keyword locks value
const int CodeA = rand() % Difficulty + Difficulty; //Declaration statement
const int CodeB = rand() % Difficulty + Difficulty; //Declaration statement
const int CodeC = rand() % Difficulty + Difficulty; //Declaration statement
const int CodeSum = CodeA + CodeB + CodeC; //Declaration statement
const int CodeProduct = CodeA * CodeB * CodeC; //Declaration statement
//printing out the variables
std::cout << "+ There are three numbers in the code"<< std::endl; //Expression statement
std::cout << "+ The 3 codes add-up to give: " << CodeSum << std::endl; //Expression statement
std::cout << "+ The 3 codes multiply to give: " << CodeProduct<< std::endl; //Expression statement
std::cout << std::endl;
std::cout << "ENTER THE CODE BELOW\n";
int GuessA, GuessB, GuessC;
std::cin >> GuessA; //Accepts user values to store in the variable
std::cin >> GuessB;
std::cin >> GuessC;
int GuessSum = GuessA + GuessB + GuessC;
int GuessProduct = GuessA * GuessB * GuessC;
//Checks user input with the Codes
if (GuessSum == CodeSum && GuessProduct == CodeProduct)
{
std::cout << "\nDamn I was right to choose you! the code is correct!\n";
std::cout << "\nAutomated voice: \"YOU HAVE UNLOCKED THE NEXT FLOOR...\"\n";
return true; //Boolean return type level completed
}
else
{
std::cout << "\nAutomated Voice: \"THE CODE YOU HAVE ENTERED IS WRONG!\"\n";
std::cout << "\nThe code is wrong what are you doing, oh my god there's a turrent turning towards me\n";
std::cout <<"\nBANG! BANG! BANG!\n";
std::cout << "\nYOU LOST\n";
std::cout << "\nRETRY\n";
return false; //Boolean return type level failed
}
}
int main() //Retuens integer
{ PrintStory();
int LevelDifficulty = 1;
const int MaxLevel = 3;
while (LevelDifficulty <= MaxLevel) //It loops the game until all levels are cleared
{
bool bLevelComplete = PlayGame(LevelDifficulty);
std::cin.clear(); //clears any error
std::cin.ignore(); //discards the buffer
if (bLevelComplete)
{
++LevelDifficulty; //increases the level difficulty, although I am using it as decreasing the floor level
}
}
std::cout <<"\nNow I can breath some fresh air, thank you and bye. Don't worry I will return the favor soon\n";
return 0; //Return statement
}