How to show another Statement

Hello All,

New here and really enjoying the course thus far. I have a question regarding showing another statement as opposed to running the same introduction. Ex: I run the program, PrintIntroduction() is provided then level completion after solving the first code. I would like to display another statement versus a repeat of my PrintIntroduction(). I believe I may need to create another function in order for it to pass through but need some guidance as knowing how to pass them. Thank you so much for expanding this knowledge!!!

Picture1

Could you give an example(s)? Also that screenshot is a bit small.

Hi Dan,

Thank you for responding to my inquiry. So in a nutshell, I would like the game to print another statement from another function. Ex: After the player completes the first challenge and the game repeats. I would like the game to state the action under the void PrintAccess(int Difficulty) function as opposed to stating the introduction all over again. My apologies if the image still appears small.

Picture1 (2)

By example I meant example output. I’m trying to determine what you’re after and how to best achieve that desired output.

Hi Dan,

Now I understand what you asking for.

Picture1

When I player enters the wrong code. I want the program to measure the number of attempts used and to notify the player of the attempts being used as highlighted in the while loop above. Thus far, I can only get the “Access Granted” to print when the code is accurate; however, I cannot get the remainder of the code to execute with the other statements prior to the code terminating when the code is entered incorrectly. The code automatically terminates with the “final” else statement without giving the player another attempt. Please see below for output.

Picture2

Picture3

Ah now I understand, basically wanting a lives feature?

Then I would suggest removing those messages completely from PlayGame and then handle all output in main.

// In PlayGame()
return CodeSum == GuessSum && CodeProduct == Code Sum


// in main()

int Attempts = 0;

while (/* ... */)
{
    bool bLevelComplete = PlayGame(Difficulty);
    if (bLevelComplete)
    {
        // ...
    }
    else if (Attempts == ...)
    {
        // ....
        Attempts++;
    }
    // ...
}

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

Privacy & Terms