Duplicate Case Value Error Arduino
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack duplicate case value previously used here Overflow the company Business Learn more about hiring developers or posting ads with us Stack duplicate case value c++ Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up In a switch case statement, it says “duplicate case value” comes up as an error. Anyone know why? up vote 2 down vote favorite 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? c++ switch-statement dev-c++ share|improve this question asked Jun 20 '13 at 22:39 user2457666 67127 2 rock1 || rock2 || rock3 evaluates to true (1), like scissors1 || scissors2. You need separate labels, but can use fall-through, case rock1: case rock2: case rock3: c = 1; break;. –Daniel Fischer Jun 20 '13 at 22:41 1 You can't use || in case statements. Sorry :( –Mooing Duck Jun 20 '13 at 22:41 6 Wouldn't it have been a better design to have chosen an enum like { rock, scissors, paper }, and then simply structured your random number generator to provide the necessary statistical percentiles? –Robert Harvey♦ Jun 20 '13 at 22:43 thanks guys! that was all really helpful. now the program works. –user2457666
Programming Boards C++ Programming 'Duplicate case value' error with chars. Getting started with C or C++ | C Tutorial | C++ Tutorial | C and C++ FAQ | Get a compiler | Fixes for common problems Thread: 'Duplicate case value' error with chars. Thread Tools Show Printable Version Email this Page… Subscribe to this Thread… Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode 05-28-2005 #1 Mr Newbie View Profile View Forum Posts Perma-Newbie Join Date Feb 2005 Posts 7 'Duplicate case value' error with chars. I want to http://stackoverflow.com/questions/17225023/in-a-switch-case-statement-it-says-duplicate-case-value-comes-up-as-an-error give a variable a value according to the value of a char within a string. For example, if (in[12] == z) y = 8; So what I've done is assign some const chars, and I'm using a switch... case to assign the values. I keep getting 'duplicate case value' errors from the line with "case (V): y = 5; break;" onwards, and my compiler tells me http://cboard.cprogramming.com/cplusplus-programming/65991-duplicate-case-value-error-chars.html that the case value was previously used in the previous line. What am I doing wrong? Code: //... const char I = ('i'||'I'); const char V = ('v'||'V'); const char X = ('x'||'X'); const char L = ('l'||'L'); const char C = ('c'||'C'); const char M = ('m'||'M'); const char operators = ('/'||'*'||'+'||'-'); //... for (i = 0, x = 0; i < 256, in[i] != '\0'; i++) { if (in[i] != operators) { switch (in[i]) { case (I): y = 1; break; case (V): y = 5; break; case (X): y = 10; break; case (L): y = 50; break; case (C): y = 100; break; case (M): y = 1000; break; default: cout<<"Oh ......... Something's gone wrong."; break;} /* code to do something with y before the cycle starts again and it's changed */ } Yes, it's a roman numeral calculator . Last edited by Mr Newbie; 05-28-2005 at 10:36 AM. 05-28-2005 #2 Salem View Profile View Forum Posts and the hat of int overfl Join Date Aug 2001 Location The edge of the known universe Posts 34,459 > const char I = ('i'||'I'); This isn't what you think it is. In particular,
but I'm getting an error. Here's the code. 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include
»arduinocommentsWant to join? Log in or sign up in seconds.|Englishlimit my search to /r/arduinouse the following search parameters to narrow your results:subreddit:subredditfind submissions in "subreddit"author:usernamefind submissions by "username"site:example.comfind submissions from "example.com"url:textsearch for "text" in urlselftext:textsearch for "text" in self post contentsself:yes (or self:no)include (or exclude) self postsnsfw:yes (or nsfw:no)include (or exclude) results marked as NSFWe.g. subreddit:aww site:imgur.com dogsee the search faq for details.advanced search: by author, subreddit...this post was submitted on 03 Apr 20151 point (60% upvoted)shortlink: remember mereset passwordloginSubmit a new linkSubmit a new text postarduinosubscribeunsubscribe66,873 readers~66 users here nowA reddit for all things Arduino. Arduino Information: Language Reference Examples Homepage Arduino to Breadboard Arduino Forum Arduino IRC Ard