I have a problem on lesson 27 regarding the while statement.
I’m pretty sure i have written the right code, but after i input the 3 digits and get the results, the code doesn’t start over, it just stays there like the “while” statement doesn’t exist. Here’s all of the code, in case someone can figure it out for me…
#include
void Printintroduction()
{
std::cout << "\n\nYou're a secret agent trying to break into a secured server room...\n";
std::cout << "You have to insert the correct code on the padlock to unlock the door...\n\n";
}
void PlayGame()
{
Printintroduction();
//Declaring the 3 number code
const int CodeA = 4;
const int CodeB = 7;
const int CodeC = 9;
int CodeSum = CodeA + CodeB + CodeC;
int CodeProduct = CodeA * CodeB * CodeC;
//Print codesum and codeproduct
std::cout << "There are three numbers in the code:";
std::cout << "\n-The numbers add up to: " << CodeSum;
std::cout << "\n-The numbers multiply to give: " << CodeProduct << std::endl;
//Player input code
int GuessA, GuessB, GuessC;
std::cin >> GuessA >> GuessB >> GuessC;
//Results Code
int GuessSum = GuessA + GuessB + GuessC;
int GuessProduct = GuessA * GuessB * GuessC;
if(GuessSum == CodeSum && GuessProduct == CodeProduct)
{
std::cout << "\nAccess Granted";
}
else
{
std::cout << "\nAcces Denied, Initializing Security Measures";
}
}
int main()
{
while(true)
{
PlayGame();
}
return 0;
}
Thanks a lot to whoever can solve this weird problem!