C++ Project Rock Paper Scissor

I am writing the project in c++ that is the rock paper and scissor one.
After writing a few lines I am experiencing a bug.

This is the link for my code

The random numbers that are generated are 2,2,3 every time I try to compile it.
1 does not come.

What should I do in This Program?

You need to use #include<time.h> at the top of the file if you want to use time(NULL) as this package contains the program. After doing that, printing out the computer variable gave me a number between 1 and 3 as expected.

I really tried it, but its not happening can you share the piece of code that you wrote to check it.
also adding #include<time.h> is making no difference.

All I did was copy and paste your code and insert #include<time.h> at the top so I’m not sure what the issue could be on your end.

#include<iostream>
#include<stdlib.h>
#include<time.h>

int main(){

srand (time(NULL));

int computer = rand() % 3+1;

std::cout << computer; // for checking the random variable

int user = 0;

std::cout << "====================\n";
std::cout << "rock paper scissors!\n";
std::cout << "====================\n";

std::cout << "1) ✊\n";
std::cout << "2) ✋\n";
std::cout << "3) ✌️\n";

std::cout << "shoot! ";
std::cin>>user;

if(computer==user)
{
  std::cout<<"Whoa! It is a tie";
}

}
1 Like

Thanks
I don’t know but after I typed this code it is suddenly correct

@adamgaffney137183916 I completed my project Thanks

@adamgaffney137183916 Hi

Glad to hear it, and happy to help!

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