switch E1578

Problems with line 25.
number "3" gets underlined and puts out an error message " E1578 case label value has already appeared in this switch at line 22"
if i remove "1" from line 22 the error goes away.


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
#include <iostream>
#include <string>

using namespace std;

int main()
{
	//här skrivs den huvudsakliga programkoden....
	int points, grade;
	

	cout << "enter points  " << endl;
	cin >> points;


	grade = 0.25*points - 1.5;

	switch (grade) {
		case 0:
			cout << " vitsordet = 0 som är underkänt " << endl;
			break;
		case 1 && 2:
			cout << " vitsordet = 1 som är nöjaktigt" << endl;
			break;
		case 3 && 4: // "3" gets underlined
			cout << "vitsordet = 3" << endl;
			break;
		case 5:
			cout << "vitsordet = 5 som är utmärkt" << endl;
		default: 
			cout << "dont cheat" << endl;
	}





	system("pause");
	return 0;
}
You can't use expressions as case labels (you can but it's not going to do what you expect) so instead you have to write two of them after each other.

1
2
3
4
case 1:
case 2:
	cout << " vitsordet = 1 som är nöjaktigt" << endl;
	break;

Topic archived. No new replies allowed.