I'm a little stumped as I rewrite for the third time

So I tried starting from scratch without going through the videos just to rebuild a cleaner foundation in hopes of making it easier to troubleshoot, but somehow I get a whole a different output for the product hint every time…

//Basic functions such as cout/cin
#include <iostream>

const std::string Intro = "\n\n    Welcome to my game!\n    Crack the 3 digit code on each level to move on!\n";
const std::string SumHint = "\n  The Numbers Add Up To: ";
const std::string ProductHint = "\n  The Numbers Multiply Out To: ";
const std::string InputCode = "\n\n    Input Code: ";

bool PlayGame()
{
    int Level;
    int CodeA = 1;
    int CodeB = 2;
    int CodeC = 3;
    int CodeSum = CodeA+CodeB+CodeC;
    int CodeProduct = CodeA*CodeB*CodeC;
    
    int CodeInputA;
    int CodeInputB;
    int CodeInputC;
    int InputSum;
    int InputCode;
    
    std::cout << Intro;
    
    std::cout << SumHint << CodeSum << ProductHint << CodeProduct << InputCode;
    std::cin >> CodeInputA >> CodeInputB >> CodeInputC;
    
    return false;
}

int main()
{
    bool bLevelComplete = true;
    while(bLevelComplete)
    {
       bLevelComplete=PlayGame();
    }
    return 0;
}

InputCode is uninitialised. Reading the value of an uninitialised variable is “undefined behaviour” which quite literally means anything can happen as the standard doesn’t say what should happen.

What you are seeing is a result of that.

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

Privacy & Terms