Issue with rand() % 2

Hello, having an issue with the last section of the TripleX game code:

I’m following the video for the random numbers part, typing in:

std::cout >> rand() % 2 “\n”;

And keep getting this error when I compile:

triplex.cpp:56:12: error: expected ‘;’ after expression
triplex.cpp:56:7: warning: expression result unused [-Wunused-value]
1 warning and 1 error generated.

Anybody got any ideas?

Thank you

Try flipping the arrow direction so that it says:

std::cout << rand() % 2 “\n”;

If that doesn’t work, also try outputting twice like this:

std::cout << rand() % 2 << “\n”;

  • Community Novice


The second one worked. I forgot the second set of arrows.

Thank you

Another issue I’m having is, in the TripleX game, my level number keeps appearing at the beginning of the next line when it should be at the end of the line above and I’m struggling to figure out why.

Now you are doing: 2 new lines + “You are a secret agent” + new line+Difficulty+ “Enter the correct…”. If you want the number at the end of the first line, you need to delete the \n after agent and put it before “Enter …” (or after Difficulty):

std::cout <<"\n\nYou are a secret agent " << Difficulty << "\n";
std:cout << "Enter the correct code to continue...  \n\n";


Thank you. That fixed it. Another that keeps happening is I keep getting a % symbol at the end with my solution and I don’t know why.

Screenshot 2021-05-02 at 09.58.15

That is to denote the end of the output i.e. you don’t end with a newline.

Cool. Seems to have disappeared. Thank you.

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

Privacy & Terms