Hey so just finished the functions lesson for TripleX, and the way I have it running vs how the instructor does at the end are different, I was wondering if there is an underlying issue with how I have mine, or if they are both perfectly fine and it just comes down to preference?
#include <iostream>
void PrintIntroduction()
{
//Print initial message
std::cout << "\n-------------------\n";
std::cout << "| DISARM THE BOMB |\n";
std::cout << "-------------------\n\n";
std::cout << "Oh no, there is a bomb in the building and you need to disarm it!\n";
std::cout << "There is a number pad on the front, you'll need to enter the correct code to stop it...\n";
}
void PlayGame()
{
//Declare numbers
const int CodeA = 4;
const int CodeB = 6;
const int CodeC = 2;
const int CodeSum = CodeA + CodeB + CodeC;
const int CodeProduct = CodeA * CodeB * CodeC;
//Prints sum and product to the console.
std::cout << std::endl;
std::cout << "- Looks like it's a three digit code\n";
std::cout << "\n- The code adds up to " << CodeSum << std::endl;
std::cout << "\n- And it multiplies to " << CodeProduct << std::endl;
//store player guess
int GuessA, GuessB, GuessC;
std::cout << "\nWhat's the code? \n";
std::cin >> GuessA >> GuessB >> GuessC;
std::cout << "\nYour hand shakes as you enter the code: " << GuessA << GuessB << GuessC << std::endl;
int GuessSum = GuessA + GuessB + GuessC;
int GuessProduct = GuessA * GuessB * GuessC;
if(GuessSum == CodeSum && GuessProduct == CodeProduct)
{
std::cout << "\nBomb Deactivated\n";
}
else
{
std::cout << "\nBOOM!\n";
}
}
int main()
{
PrintIntroduction();
PlayGame();
return 0;
}
I call the PrintIntrodction in int main() opposed to within void Playgame()
Cheers,
Colin