Assigning values not working

I need to make a program that will determine an odd or even number and when I try to assign a value to "int o" or "int e" it says o and e are "uninitialized local variable 'name' used". The thing is I have to use a "ternary/conditional operator" and I'm unfamiliar with this.

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

using namespace std;

int main()
{
	int digit;
	int solution;
	int o, e;

	cout << "Please enter a number for me to determine if it is odd or even " << endl;
	cin >> digit;
	
	solution = digit % 2 == 0 ? solution = e : solution = o;
	
	if (solution = e)
	{
		cout << "The number you input is even " << endl;
	}
	else
	{
		cout << "The number you input is odd " << endl;
	}
	

	return 0;
}
Last edited on
Where do you assign values to e or o?

The tutorial http://www.cplusplus.com/doc/tutorial/operators/
shows the use of ternary with an example.


PS. You do have an assignment on line 16. Should you rather compare values there?
Why do you even need e or o?

Why not something like:

1
2
3
4
5
6
7
8
9
10
11
12
13
int main()
{
	int digit;
	bool solution;

	cout << "Please enter a number for me to determine if it is odd or even " << endl;
	cin >> digit;

	solution = digit % 2 ? false : true;

	if (solution)
	{
		cout << "The number you input is even " << endl;)

Topic archived. No new replies allowed.