Void PrintIntroduction();

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

Later on PlayGame will be called within a loop which if you had PrintIntroduction in there would mean it would be called every loop which is probably something you don’t want.

I believe Gavin moves it outside of PlayGame in a couple lectures time because of that.

Perfect Cheers Dan.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms