I'm setting up a program that will create a random number 1-3 and then assigns that number a certain property i.e. R,P,S (Rock, Paper, or Scissors).
I then test that number and turn the value of my variable into either "Rock, Paper, or Scissors"
Is there a way to do this that isn't as redundant then just typing in each scenario. I'm assuming it deals with some sort of loop, but am not quite sure. Sorry if these questions seem poor as I'm just learning and trying to figure out the most efficient way to code these scenarios.
If you see anything coded poorly please let me know!
if((weap1 == "Rock") && (cpuWeap == "Scissors"))
{
cout<<"The CPU picked Scissors!"<<endl;
cout<<"Congratulations you won!"<<endl;
}
else if ((weap1 =="Paper") && (cpuWeap == "Rock"))
{
cout<<"The CPU picked Rock!"<<endl;
cout<<"Congratulations you won!"<<endl;
}
else if ((weap1 =="Scissors") && (cpuWeap == "Paper"))
{
cout<<"The CPU picked Paper!"<<endl;
cout<<"Congratulations you won!"<<endl;
}
else if (weap1 == cpuWeap)
{
cout<<"You and the CPU picked "<<weap1<<"!"<<endl;
cout<<"It's a draw!"<<endl;
}
else
{
cout<<"The CPU picked "<<cpuWeap<<"."<<endl;
cout<<"Sorry, you lost!"<<endl;
} }