Rock Paper Scissors question bracket quesiton

I was wondering how come the if statements on this code doesn’t have "{ " for certain parts of it? When writing it. I assumed it needed it. But when I compiled the code I got errors.

#include

#include <stdlib.h>

/*

Rock Paper Scissors Lizard Spock

(The Big Bang Theory)

*/

int main () {

// Live long and prosper

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 << "shoot! ";

std::cin >> user;

if (user == 1)

std::cout << "you choose: ✊\n";

else if (user == 2)

std::cout << "you choose: ✋\n";

else

std::cout << "you choose: ✌️\n";

if (computer == 1)

std::cout << "cpu choose: ✊\n";

else if (computer == 2)

std::cout << "cpu choose: ✋\n";

else

std::cout << "cpu choose: ✌️\n";

if (user == computer) {

std::cout << "it's a tie!\n";

}

//// ROCK

else if (user == 1){

if (computer == 2) {

std::cout << "You Lost \n";

}

if (computer == 3){

std::cout << "You Won \n";

}

}

//// Scisssors

else if (user == 2){

if (computer == 1) {

std::cout << "You Won \n";

}

if (computer == 3){

std::cout << "You Lost \n";

}

}

///// Paper

else if (user == 3){

if (computer == 1) {

std::cout << "You Lost \n";

}

if (computer == 3){

std::cout << "You Won \n";

}

return 0;

}

}

Hi :slight_smile:

In C++ you can do one-line if statements without brackets! I personally don’t like it so I always end up using brackets (and I’m sure certain teams have style guides laying down whether this should be the norm or not).

For future posts, keep in mind that it’s vital to format your code when you post: [How to] Format code in posts