Error on matching operands

Just finishing a Menu project but when trying to add a convert from decimal to base, I receive this Error on line 142:

E0349 no operator "<" matches these operands
Error C2678 binary '<': no operator found which takes a left-hand operand of type 'std::basic_ostream<char,std::char_traits<char>>' (or there is no acceptable conversion)


What should I change or add to be able to build?

Thanks!


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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
  // Calc.cpp : Defines the entry point for the application.
//

#include "Calc.h"
#include "stdafx.h"
#include <iostream>
#include <cctype>
#include <stdio.h>
#include <cstdio>
#include <cstdlib>
#include <string>
using namespace std;
char menu1();
int addition(int a, int b);
void substraction(int a, int b);
int multiplication(int a, int b);
double circle(int a);
int triangle(int a, int b);
int square(int a);
void evenodd(int q);
int division(int a, int b);
int factorial(int a);
double exponent(int a, int b);
int realdivision(int a, int b);
int quotient(int a, int b);
int remainder(int a, int b);
void convertatob(int a, int b);

//Calcualtor Menu
char menu1()
{
	char choice = 'Z';
	while ((choice > 'O') || (choice < 'A'))

	{
		cout << "Enter O to quit\n";
		cout << "Enter A for Addition\n";
		cout << "Enter B for Area of a Circle\n";
		cout << "Enter C for Area of a Right triangle \n";
		cout << "Enter D for Area of a Square \n";
		cout << "Enter E for Convert decimal to bases 2 - 16 \n";
		cout << "Enter F for Exponent of 2 integers \n";
		cout << "Enter G for Get Factorial \n";
		cout << "Enter H for Even/odd \n";
		cout << "Enter I for Integer Division \n";
		cout << "Enter J for Get real division of 2 integers \n";
		cout << "Enter K for Multiplication \n";
		cout << "Enter L for Quotient of 2 numbers \n";
		cout << "Enter M for Remainder of 2 integers \n";
		cout << "Enter N for Substraction \n";
		cin >> choice;
		choice = toupper(choice);					//Convert to non-case-sensitive
	}
	return choice;

}

//Calculator Menu Printout

int _tmain(int argc, _TCHAR* argv[])
{
	int choice, i1, i2;
	char s1[4], s2[4];
	choice = menu1();
	if (choice == 'O')
		return 0;
	cout << "Enter number x: ";
	cin >> s1;
	i1 = atoi(s1);
	if ((choice != 'G') && (choice != 'H') && (choice != 'B') && (choice != 'D'))
	{
		cout << "Enter number y: ";
		cin >> s2;
	}
	i2 = atoi(s2);
	if (choice == 'A')
		cout << addition(i1, i2) << endl;
	else if (choice == 'B')
		cout << "Area of circle: " << circle(i1) << endl;
	if (choice == 'C')
		cout << "Area of a Right triangle: " << triangle(i1, i2) << endl;
	else if (choice == 'D')
		cout << "Area of square: " << square(i1) << endl;
	if (choice == 'E')
		convertatob(i1, i2);
	if (choice == 'F')
		cout << " The power of " << i1 << " to the " << i2 << " = " << exponent(i1,i2) << endl;
	else if (choice == 'G')
		cout << "The answer is: " << factorial(i1) << endl;
	else if (choice == 'H')
		evenodd(i1);
	if (choice == 'I')
		cout << division(i1, i2) << endl;
	if (choice == 'J')
		cout << "The division of " << i1 << " and " << i2 << " is: "<< realdivision(i1, i2) << endl;
	if (choice == 'K')
		cout << multiplication(i1, i2) << endl;	
	if (choice == 'L')
		cout << "The quotient of integer x: " << i1 << " and integer y: " << i2 << " is: " << quotient(i1, i2) << endl;
	if (choice == 'M')
		cout << "The remainder of integer x: " << i1 << " and integer y: " << i2 << " is: " << remainder(i1, i2) << endl;
	else if (choice == 'N')
		substraction(i1, i2);
}

//Addition: Choice 'A'
int addition(int a, int b)
{
	return(a + b);
}

//Area of a circle: Choice 'B'
double circle(int a)
{
	return (3.14*a*a);
}

//Area of a right triangle: Choice 'C'
int triangle(int a, int b)
{
	return(((a*b) / 2));
}


//Area of a square: Choice 'D'
int square(int a)
{
	return(a * a);

}

//Convert decimal to bases 2 - 16: Choice 'E'
void convertatob(int a, int b)
{
	if (a == 0)
		return;
	int x = a % b;
	a /= b;
	if (x < 0)
		a += 1;
	convertatob(a, b);
	cout << x < 0 ? x + (b * -1) : x;
	return;
}

//Exponent of 2 integers: Choice 'F'
double exponent(int a, int b)
{
	return( pow(a, b));
}

//Factorial: Choice 'G'
int factorial(int a)
{
	int m, fact = 1;

	for (m = 1; m <= a; m++)
	{
		fact = fact * m;
	}
	return fact;
}

//Even/Odd: Choice 'H'
void evenodd(int q)
{
	if (q % 2 == 0)
		cout << "Number " << q << " is even\n";
	else cout << "Number " << q << " is odd\n";
}

//Integer Division: Choice 'I'
int division(int a, int b)
{
	return(a / b);
}

//Division of two real numbers: Choice "J"
int realdivision(int a, int b)
{
	return(a / b);
}

// Multiplication: Choice 'K'
int multiplication(int a, int b)
{
	return(a*b);
}

//Quotient of 2 numbers: Choice 'L'
int quotient(int a, int b)
{
	return(a / b);
}
//Remainder of 2 integers:
int remainder(int a, int b)
{
	return(a % b);
}

//Substraction: Choice 'N'
void substraction(int a, int b)
{
	cout << a << " - " << b << " = " << a - b << endl;
}
Last edited on
That line of code need () around the conditional expression
Hello vacisneros,

One I see is line 142 you have cout << x < 0 ? x + (b * -1) : x . It is thinking that "<" is part of "cout" thus causing the error. What it should be is cout << ((x < 0 ?) x + (b * -1) : x). Notice the extra ()s to make this work, especially at the beginning. Experience has taught me that a set of () around the whole expression work the best.

Hope that helps,

Andy
Hey Andy,
Thank you for the reply!
I replaced the line to what you suggested but now it is giving me this error:

"expected an expression", "expected a ')'", "syntax error: ')'"
and it's returning the code with red lines under the part after:

cout << ((x < 0 ?


Meaning, under this part:
) x
what else should I change?

Thanks !!
Last edited on
Post the actual line of code, sounds like you forgot a closing parenthesis.
Last edited on
((x < 0 ?) x + (b * -1) : x)
should be ((x < 0)? x + (b * -1) : x)
or simply (x < 0 ? x + (b * -1) : x)
Worked! Thanks ne555!!
Registered users can post here. Sign in or register to post.