Error Duplicate Case Value In Switch
Contents |
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 Overflow the duplicate case value previously used here company Business Learn more about hiring developers or posting ads with us Stack Overflow
Arduino Duplicate Case Value
Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 duplicate case label million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up switch statement duplicate error up vote -1 down vote favorite #include
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
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 http://cboard.cprogramming.com/cplusplus-programming/65991-duplicate-case-value-error-chars.html 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 give a variable a value according to the value of a char within a string. For example, duplicate case 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 that the case value was previously used in the previous line. What am I doing wrong? Code: //... const char I = ('i'||'I'); const char duplicate case value 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,467 > const char I = ('i'||'I'); This isn't what you think it is. In particular, it isn't a value which specifically matches two cases of the same letter. By the time you've done the same trick to several letters, you have duplicate values. Scrap all the const chars, and do this Code: switch ( toupper(in[i]) ) { case 'I': y = 1; break; case 'V': y