Sunday, 15 May 2011

c++ - In a switch case statement, it says "duplicate case value" comes up as an error. Anyone know why? -


I am working on a rock paper shears program, but this time the computer has selected the rock in half time, One-third of the scissors, and the paper is only a sixth of the time. The way I did this, I calculated six possible computer preference values:

  enum choicec {rock1, rock2, rock3, scissors1, scissors2, paper}; Election computer;   

But then, after the computer's own choice, I have to convert these enumerated values ​​into rock, paper or scissors. I did this using a switch-case statement:

  switch (computer) {case rock 1 || Rock 2 || Rock 3: C = 1; break; Hair scissors 1 || Scissors 2: // Error! C = 3; break; Case paper: c = 2; break; }   

There is a rock, two papers, and three scissors. However, on the line where I have an error written in the form of a comment, it gives me this error: [Error] Duplicate Case Value.

I'm not sure why any thoughts?

I'm not sure what you are doing, but switch statement should look like this

 Switch (computer) {Case Rock 1: Case Rock 2: Case Rock 3: C = 1; break; Case shears 1: Hair scissors 2: C = 3; break; Case paper: c = 2; break; }    

No comments:

Post a Comment