Am I doing something wrong?

This is the message that I’m currently receiving with my code in VS, every time I try to run the Triple X game in mac. I’ve also included the code bellow.

#include <iostream>

void PrintIntroduction()
   //Introduction Text
    std::cout << "\nYou need to access the code to be able to win Big Ideas!";
    std::cout << "\n\nFind the right codes to shut Big Ideas down!";


void PlayGame()
{
    PrintIntroduction();
    // Declare 3 number code
    const int CodeA = 4;
    const int CodeB = 3;
    const int CodeC = 2;

    const int CodeSum = CodeA + CodeB + CodeC;
    const int CodeProduct = CodeA * CodeB * CodeC;

    //Print CodeSum and CodeProduct to the terminal
    std::cout << std::endl;
    std::cout << "+ There are 3 numbers in the code" << std:: endl;
    std::cout << "\n+ The numbers add-up to: " << CodeSum;
    std::cout << "\n+ The codes multiply to give: " << CodeProduct << std:: endl;
    std::cout << CodeProduct << std::endl;

    // Store player guess
    int GuessA, GuessB, GuessC;
    std::cin >> GuessA;
    std::cin >> GuessB;
    std::cin >> GuessC;

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

    // Check if the players guess is correct
    if (GuessSum == CodeSum && GuessProduct == CodeProduct)
    {
    std::cout << "\nYou Win!";

    }
    else 
    {
    std::cout << "\nCarole from Big Ideas here! You've got a 10,000 word essay due for tomorrow! (Oh by the way we'll teach you fuck all in today's lecture) :)";
    }  
}

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

You missed some curly braces around your PrintIntroduction() function’s body.

Forgive me for being stupid as I’m knew to all the C++ and game dev coding but which line are you referring to specifically because I have the following line (if this is what you are referring to?):

void PlayGame()
}
      PrintIntroduction();

but then I also have the this line (bellow the #include <iostream>):

void PrintIntroduction()
   //Introduction Text
    std::cout << "\nYou need to access the code to be able to win Big Ideas!";
    std::cout << "\n\nFind the right codes to shut Big Ideas down!";

Thanks!

If you look at your PlayGame method, can see that all of the code is surrounded by curly braces. When writing a function in C++, that is required. So, a function looks similar to this:

void PrintIntroduction()
{
  // Your code here
}

In your case, you have something like this:

void PrintIntroduction()
  // Your code here

The missing pieces are the curly braces. Put those in, and that particular error will go away.

Got you now! Thanks so much for the help! Because I’ve been staring at my code for so long I’ve missed little mistakes like that and sometimes getting another pair of eyes to read my code helps!

Thanks a lot.

I managed to fix that issue okay and it got rid of the problem but when I came to compile the code in VS for mac it came back with an issue within the int main (true) function with the following error message:

I tried compiling the code twice so there are two versions of the same error message printed but it was pointing at the ; after the top level declarator which I guess is from the PlayGame();

Is it telling me this because I don’t have a PlayGame element further up in the code so it can’t close the PlayGame(); function?

Also, here is the following code I have that is providing the error:

int main (true)
{
    while (true)
    {
         PlayGame();
    }

Thanks.

That error is simply because you do not need the true in int main (true); it should just be int main().

As you work through this, you should compare your code to the sample code from time to time. It does not necessarily have to match line-by-line, but you can note the differences to help you determine what might not work in your code.

Of course, if you get stuck even after doing that, the community is here to help!

Thanks alot! You’ve been a big help! :smiley:

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

Privacy & Terms