Need help with a similair game to TripleX

Ill put my code underneath, the problem im getting is its running the program more than once and that it is not displaying the “nice” message if you guess the correct numbers.

#include <iostream>
#include <ctime>

void PrintIntroduction()
{
    std::cout << "You wander into a magical forest full of monsters. \n";
    std::cout << "you must complete number based puzzles to kill them!\n";
}

int RandomMonster()
{
    int Monster = rand() % 4 + 1;
    return Monster;
}

bool Dragon(int Difficulty)
{
    
    std::cout << "A dragon attacks you!\n";
    const int NumA = rand() % Difficulty + Difficulty;
    const int NumB = rand() % Difficulty + Difficulty;

    const int NumSum = NumA + NumB;
    const int NumProduct = NumA * NumB;

    std::cout << "The two numbers add up to: " << NumSum << std::endl;
    std::cout << "The two numbers multiply to make: " << NumProduct << std::endl;

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

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

    if (GuessSum == NumSum && GuessProduct == NumProduct)
    {
        return true;
    } else
    {
        return false;
    }
    

}


int main()
{  

    srand (time(NULL));

    PrintIntroduction();

    bool PlayerAlive = true;
    while(PlayerAlive) 
    {
        if (RandomMonster() == 1){
            bool DragonComplete = Dragon(5);
            if (DragonComplete == true)
            {
                std::cout << "nice";
                return 0;
            }
        } else if(RandomMonster() == 2)
        {
            return 0;
        } else if(RandomMonster() == 3)
        {
            return 0;
        } else
        {
            return 0;
        }
        
    }
    return 0;
}

GuessB is left uninitalised.
Here you need >> not ,

This topic was automatically closed after 6 days. New replies are no longer allowed.