I am working on a rock paper scissors program, but this time the computer chooses rock half the time, scissors a third of the time, and paper only one sixth of the time. The way I did this was I enumerated six possible computer choice values:
enum choicec {rock1, rock2, rock3, scissors1, scissors2, paper};
choicec computer;
But then, after the computer makes its choice, I have to convert these enumerated values to either rock, paper, or scissors. I did this using a switch-case statement:
switch(computer) {
case rock1 || rock2 || rock3:
c = 1;
break;
case scissors1 || scissors2: //ERROR!
c = 3;
break;
case paper:
c = 2;
break;
}
one is rock, two is paper, and three is scissors. However, on the line where I have error written in as a comment, it gives me this error: [Error] duplicate case value.
I'm not sure why. Any ideas?
rock1 || rock2 || rock3
evaluates to true (1), likescissors1 || scissors2
. You need separate labels, but can use fall-through,case rock1: case rock2: case rock3: c = 1; break;
. – Septime||
incase
statements. Sorry :( – Oshea{ rock, scissors, paper }
, and then simply structured your random number generator to provide the necessary statistical percentiles? – Tilefish