nested if, else if loop not working

I need to create a nested if, else if loop, but no matter what I do I can't seem to get it to work right, even though it seems like I'm doing exactly what the example sheets show us.

Instead of running the statement indicated by the arithmetic character, it always runs the addition loop. Could anyone point out what I'm doing wrong? Thanks in advance.

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
 #include <iostream>
using namespace std ;

double numOne ;
double numTwo ;
double output ;
char arithmetic ;


int main() 
{
	cout<<"FLEXIBLE ARITHMETIC CHOICE"
		<<endl ;
	cout<<"By blah blah"
		<<endl ;

	cout<<"Please enter the first number: " ;
		cin>>numOne ;
			cout<<endl ;
	cout<<"Please enter the second number: " ;
		cin>>numTwo ;
			cout<<endl ;
	cout<<"Please enter the desired arithmetic symbol: " ;
		cin>>arithmetic ;

	
	if(arithmetic == 'A', 'a', '+')
	{
		output = numOne + numTwo ;
			cout<<"The solution is: "
				<<output
					<<endl ;
	}
	else if(arithmetic == 'M', 'm', '-')
	{
		output = numOne - numTwo ;
			cout<<"The solution is: "
				<<output
					<<endl ;
	}
	else if(arithmetic == '*')
	{
		output = numOne * numTwo ;
			cout<<"The solution is: "
				<<output
					<<endl ;
	}
	else if(arithmetic == 'D', 'd', '/')
	{
		output = numOne / numTwo ;
			cout<<"The solution is: "
				<<output
					<<endl ;
	}
	else
	{
		cout<<"Not a valid arithmetic character."
			<<endl ;
	}

	return 0 ;

}
Try this:

if(arithmetic == 'A' && arithmetic == 'a' && arithmetic == '+')

The comma operator does not do what you think it does - always research how things work rather than assuming :-)

Also, it isn't good practice to use global variables - put them in main().

Hope all goes well !
Actually, the above will not work as well. arithmetic cannot be three things at once. Try || instead of &&.
Sorry, My bad - must be still asleep !
Thanks for the quick responses, guys. @Ispil's suggestion worked, and now everything's working correctly. Starting to feel like I'm not cut out for this stuff, but whatever, gotta power through lol
Topic archived. No new replies allowed.