Rock, Paper, Scissors - Can't get past compiling error!

I’m having trouble finishing this project and I need help before my laptop goes out the window!

When I compile from this line:

if (user == computer) {

std::cout << “The game is a tie!\n”;
}

}

It compiles with no issues but as soon as I start adding in the rest of the code it says:

rock_paper_scissors.cpp: In function ‘int main()’:
rock_paper_scissors.cpp:108:1: error: expected ‘}’ at end of input
}
^
I’ve tried using the code from the example but it still has the same issue, I’m so confused! It seems my code should work but obviously I’m missing something.

Links: - https://github.com/Codecademy/learn-cpp/blob/master/3-conditionals-and-logic/rock-paper-scissors-lizard-spock/RPS.cpp

My code so far:

/*
Good ol’ rock, paper, scissors.
*/

#include
#include <stdlib.h>

int main() {

// Let’s get this thing working.

srand (time(NULL));

int computer = rand() % 3 + 1;

int user = 0;

std::cout << “====================\n”;
std::cout << “Rock, paper scissors!\n”;
std::cout << “====================\n”;

std::cout << “1) :fist:\n”;
std::cout << “2) :raised_hand:\n”;
std::cout << “3) :v:\n”;

std::cout << "Make your move… ";

std::cin >> user;

if (user == 1) {

std::cout << “Player chooses :fist:\n”;
}

else if (user ==2) {

std::cout << “Player chooses :raised_hand:\n”;
}

else {

std::cout << “Player chooses :v:\n”;
}

if (computer == 1) {

std::cout << “Computer chooses :fist:\n”;
}

else if (computer == 2) {

std::cout << “Computer chooses :raised_hand:\n”;
}

else {

std::cout << “Computer chooses :v:\n”;
}

// Tied outcome.

if (user == computer) {

std::cout << “The game is a tie!\n”;
}.

// Compiling error from this point onwards.

else if (user == 1) {

if (computer == 2) {

std::cout << "You have been defeated...\n";

}

if (computer == 3) {

std::cout << "You are victorius!\n";

}

else if (user == 2) {

if (computer == 1) {

std::cout << "You are victorius!\n";

}

if (computer == 3) {

std::cout << "You have been defeated...\n";

}

else {

if (computer == 1) {

std::cout << "You have been defeated...\n";

}

if (computer == 2) {

std::cout << "You are victorius!\n";

}

}

Hey there @nicholassmith6736565 and welcome to the forums! :grinning:

It would appear you attempted to format your code, but it did not end up quiet right, to format properly all you have to do is click this button:

And copy/paste all of your code between the two lines of back ticks:


There are a few errors in the code provided, though I think this may be slightly different than yours if this statement is true:

Your error message is stating that you are missing }.
Note that for every opening curly bracket { you start a block of code, that must be closed before the file can compile.
Try counting how many opening brackets you have compared to closed ones.

2 Likes

Hiya,

Thanks very much for your response @8-bit-gaming! I will bear in mind what you said about formatting code in the future.

I’ll check the number of closed brackets and get back to you. When comparing my code to the example code it seems that they’re pretty much identical so that’s why I’ve been trying to wrap my head around why mine isn’t compiling.

1 Like

Here’s a little tip!

If you highlight a curly bracket “{” or “}” in your code, the corresponding curly bracket should automatically become highlighted.

It’s an incredibly handy feature common to most IDE’s to make sure everything is in it’s correct place.

Scroll to the bottom of your code and highlight the last “}”, then scroll all the way up. You should see the very first “{” highlighted in your code:

int main(){

If another is highlighted instead, then you need to correct the number of of curly brackets you’re using, or their placement.

Hope this helps!

1 Like

Hi @leohunter1687938132,

This is an invaluable tip and I used it to help me complete the project, thank you for your help :slight_smile:

1 Like