My final TripleX code

#include <iostream>
#include <ctime>

void PrintIntro(int ChannelCount)
{
    std::cout << "\n\nUghh, they have satellite TV... haven't they ever heard of Netflix?\n";
    std::cout << "I need to find a channel with something interesting, but there are hundreds of channels...\n";
    std::cout << ChannelCount << " channel(s) down, too many more to go > _ <";
}

bool PlayGame(int Difficulty, int ChannelCount)
{
    PrintIntro(ChannelCount);

    const int ChannelN1 = rand() % Difficulty + Difficulty;
    const int ChannelN2 = rand() % Difficulty + Difficulty;
    const int ChannelN3 = rand() % Difficulty + Difficulty;

    const int ChannelSum = ChannelN1+ChannelN2+ChannelN3;
    const int ChannelProduct = ChannelN1*ChannelN2*ChannelN3;

    // Print hints to terminal
    std::cout << "\n\nI seem to recall that to change the channel on the TV I need to enter 3 numbers\n";
    std::cout << "What's this? A note under the remote...\n" << "It says a fantastic channel's numbers added together are " << ChannelSum;
    std::cout << "\nand when multiplied together become " << ChannelProduct << "\nMaybe this will get me something good to watch!\n\n";

    // Store guesses
    int ChannelGuessN1, ChannelGuessN2, ChannelGuessN3;
    std::cout << "Hopefully I can solve this riddle correctly by pressing each of the three remote number buttons one at a time:\n";
    std::cin >> ChannelGuessN1 >> ChannelGuessN2 >> ChannelGuessN3;

    int ChannelGuessSum = ChannelGuessN1+ChannelGuessN2+ChannelGuessN3;
    int ChannelGuessProduct = ChannelGuessN1*ChannelGuessN2*ChannelGuessN3;

    // check if the players guess is correct
    if (ChannelGuessSum == ChannelSum && ChannelGuessProduct == ChannelProduct)
    {
        std::cout << "Oh, this is a good show... wait it's over!? Now I have to find a new channel *grrr*\n";
        std::cout << "Looks like there are more codes here to try.";
        return true;
    }
    else
    {
        std::cout << "Did I guess the wrong channel?... this is just a boring infomercial T _ T\n";
        std::cout << "Let's try another channel, looks like there are more codes to try.";
        return false;
    }
}

int main()
{
    srand(time(NULL)); // Create new random sequence based on the time

    int ChannelCount = 0;
    int LevelDifficulty = 1;
    const int MaxDifficulty = 5;

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

        if (bLevelComplete)
        {
            ++LevelDifficulty;
        }

        ++ChannelCount;
    }
    
    std::cout << "\n\nSCORE! I found my favorite movie and it's just starting! ~(^-^)~";

    return 0;
}
1 Like

Now that’s awesome looking code.

Privacy & Terms