error

[Error] case label does not reduce to an integer constant
What does this mean..
sorry i'm a beginner

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
 #include <iostream>
#include <stdlib.h>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main() {
	int num1;
	int num2;
	char choice;
	cout<<"Random number will be generated:"<<endl;
	num1=rand()%1000+1;
	cout<<num1<<endl;
	cout<<"Please enter your number: (1-100)"<<endl;
	cin>>num2;
	cout<<"Please choose an operation to execute the number:"<<endl;
	cout<<"A:Addition"<<endl;
	cout<<"b:Subtraction"<<endl;
	cout<<"C:Multiplication"<<endl;
	cout<<"D:Division "<<endl;
	return 0;
	switch(choice)
	{
	
	case "A":
	case "a":
	{
		cout<<"The answer is:"<<num1+num2<<endl;
		break;
	}
	case "B":
	case "b":
	{
		cout<<"The answer is:"<<num1-num2<<endl;
		break;
	}
	case "C":
	case "c":
	{
		cout<<"The answer is:"<<num1*num2<<endl;
		break;
	}
	case "D":
	case "d":
	{
		cout<<"The answer is:"<<num1/num2<<endl;
		break;
	}
	}
	return 0;
}
Last edited on
Text inside "" are const char* which are not allowed in switch statements in C++.

You need to use single quotes for a single char like
1
2
3
4
5
switch(choice)
{
  case 'A':
  case 'a':
}

Also have a look for toupper which will save the comparison inside the swich.
http://www.cplusplus.com/reference/cctype/toupper/

Also be aware that your return statement in line 20 ends the program so the swich will never reached.
ok,thanks alot sir :)
Topic archived. No new replies allowed.