Using if and else

Not sure why part of the code isn’t posting, but this is what i have so far.

#include

int main()
{
//print story context
std::cout << std::endl;
std::cout << “You are R2-D2. Your friends have fallen into the trash compactor and the walls are closing in.”;
std::cout << std::endl;
std::cout << “Hack into the detention level mainframe by solving a series of puzzles before its too late!”;
std::cout << std::endl;

//Declare 3 number code
const int CodeA = 2;
const int CodeB = 3;
const int CodeC = 4;

const int CodeSum = CodeA + CodeB + CodeC;
const int CodeProduct = CodeA * CodeB * CodeC;

// Print CodeSum and CodeProduct to the terminal
std::cout << "+ There are 3 numbers in the code" << std::endl;
std::cout << "+ The codes add-up to: " << CodeSum << std::endl;
std::cout << "+ The codes multiply to give: " << CodeProduct << std::endl;
std::cout << std::endl;

int GuessA, GuessB, GuessC;
std::cin >> GuessA;
std::cin >> GuessB;
std::cin >> GuessC;

int GuessSum = GuessA + GuessB + GuessC;
int GuessProduct = GuessA * GuessB * GuessC;

if (GuessSum == CodeSum && GuessProduct == CodeProduct)
{
    std::cout << "You've done it!";
}

else
{
    std::cout << "Oh no! That isn't quite right.";
}

std::cout << std::endl;

return 0;

}

#include

void PrintIntroduction(int Difficulty)
{
//print story context
std::cout << std::endl;
std::cout << “\n”;
std::cout << " __. ___ .\n";
std::cout << " / | / \ | _ \ \n";
std::cout << " | (-----| |----/ ^ \\ | |_) |\n"; std::cout << " \\ \\ | | / /_\\ \\ | /\n"; std::cout << " .-----) | | | / _____ \\ | |\\ \\-------.\n"; std::cout << " |________/ |__| /__/ \\__\\| _| .__|\n";
std::cout << " ____ __ ____ ___ .
________.\n";
std::cout << " \ \ / \ / / / \ | _ \ / |\n";
std::cout << " \ \/ \/ / / ^ \ | |
) || (-----\n"; std::cout << " \\ / / /_\\ \\ | / \\ \\ \n"; std::cout << " \\ /\\ / / _____ \\ | |\\ \\---) |\n"; std::cout << " \\__/ \\__/ /__/ \\__\\|__| .
/\n";
std::cout << “\nYou are R2-D2. Your friends have fallen into the trash compactor and the walls are closing in.\n”;
std::cout << “Hack into the detention level mainframe and by solving a series of 5 puzzles before its too late!\n\n”;
std::cout << “Level:” << Difficulty << std::endl << std::endl;

}

bool PlayGame(int Difficulty)
{
PrintIntroduction(Difficulty);

//Declare 3 number code
const int CodeA = 2;
const int CodeB = 3;
const int CodeC = 4;

const int CodeSum = CodeA + CodeB + CodeC;
const int CodeProduct = CodeA * CodeB * CodeC;

// Print CodeSum and CodeProduct to the terminal
std::cout << "+ There are 3 numbers in the code\n";
std::cout << "+ The codes add-up to: " << CodeSum;
std::cout << "\n+ The codes multiply to give: " << CodeProduct;
std::cout << std::endl;

// Store player guess
int GuessA, GuessB, GuessC;
std::cin >> GuessA >> GuessB >> GuessC;

int GuessSum = GuessA + GuessB + GuessC;
int GuessProduct = GuessA * GuessB * GuessC;

// Check if the player's guess is correct
if (GuessSum == CodeSum && GuessProduct == CodeProduct)
{
    std::cout << "\nOne of the 5 opening triggers initializes!";
    return true;
}
else
{
    std::cout << "\nHm... that doesn't seem quite right. Try again";
    return false;
}

}

int main()
{
int LevelDifficulty = 1;
int const MaxDifficulty = 5;

while (LevelDifficulty <= MaxDifficulty) // Loop the game until all levels are completed
{
    bool bLevelComplete = PlayGame(LevelDifficulty);
    std::cin.clear(); // Clears any errors
    std::cin.ignore(); // Discards the buffer

    if (bLevelComplete)
    {
        ++LevelDifficulty;
    }
    
}

std::cout << " and...\n\nYou've done it! The doors are open and your friends can escape!";
std::cout << std::endl;
return 0;

}

Privacy & Terms