Hello everyone!
I have been working on making a portfolio of projects as an exercise to improve my skills with cpp.
I coded this simple rock paper scissors games this morning.
The code runs fine, its just that the rng seems to be completely of, with the player always losing.
I think that I am either doing rng wrong, or have an error in my logic that I have not spotted.
Thanks in advance,
I2P
#include<random>
#include<iostream>
void round()
{
int selection;
std::cin>>selection;
std::random_device dev;
std::mt19937 rng(dev());
std::uniform_int_distribution<std::mt19937::result_type>dist3(1,3);
bool win=false;
int opponent=dist3(rng);
if(selection==opponent)
{
std::cout<<"tie!"<<std::endl;
}
else
{
switch(selection)
{
case 1:
if(opponent==3)
{
std::cout<<"you win!"<<std::endl;
win=true;
}
case 2:
if(opponent==1)
{
std::cout<<"you win!"<<std::endl;
win=true;
}
case 3:
if(opponent==2)
{
std::cout<<"you win!"<<std::endl;
win=true;
}
}
if(!win)
{
std::cout<<"you lose!"<<std::endl;
}
}
}
int main()
{
while(true)
{
round();
}
return 0;
}