expected a ')' "and"

Pages: 12
Hello everybody! Please help me. I just learning now, how to programming in c++.
I have an error at the line 27. "expected a ')'. There is a red line under the "and" word. Please help on me.


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
  #include <iostream>
#include <cstdlib>               
#include <math.h> 

using namespace std;

#define vesszo ","
#define szokoz " "

int main()
{
	system("cls");
	double a, b, c;

	cout << "1.oldal: ";
	cin >> a;
	cout << "2.oldal: ";
	cin >> b;
	cout << "3.oldal: ";
	cin >> c;

	cout << "A haromszog oldalai: " << a << vesszo << szokoz << b << vesszo << szokoz << c << "\n";


	bool szekhet = false;

	if ((a + b > c) and(a + c > b) and(b + c > a));

}
Try to rebuild it once more.
Your code is fine: http://ideone.com/yOW86j
You could try replacing the and with &&.


PS. Your if has an empty body: no statements to do if the condition is true.
the word "and" is BASIC I think. In C++ a logical "and" is "&&"
Last edited on
Though it is rarely used in C++, you can actually use "and" to mean the logical AND operator.
In what header file is it defined? I'm been programming C for 25 years (though most of that was GNU C) and have never seen "and" used. Of course it could be #defined in a header but I don't think its a part of C++ I think "AND" is a part of BASIC. With that error it hasn't been #define(d)

But if you want to fix it:
#define and &&
#define or ||
#define not !
Last edited on
So its a a keyboard language thing. Then I guess the compiler he is using doesn't support it.

I guess he would have to define a sequence of key codes.
Ok, from what is see it requires the iso646.h.

Operator Keyword for &&
The and operator is the text equivalent of &&. There are two ways to access the and operator in your programs: include the header file iso646.h, or compile with the /Za (Disable language extensions) compiler option.


https://msdn.microsoft.com/en-us/library/c6s3h5a7.aspx
It only requires that for c not for c++. It is part of section 2 of the 1998 c++ standard. ISO/IEC 14882:1998

Take a look http://sites.cs.queensu.ca/gradresources/stuff/cpp98.pdf

Also they are classified as "predefined preprocessor tokens" and not a "keyword" IIRC.
It should work in C++

#include<ciso646>
It literally has zero affect when you include that in c++ since they are part of the standard.
This compiles fine in Visual Studio 2013 And if you hover the mouse over the "and" you see its #define and &&

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
#include <iostream>
#include <cstdlib>               
#include <math.h> 
#include<ciso646>

using namespace std;

#define vesszo ","
#define szokoz " "

int main()
{
	system("cls");
	double a, b, c;

	cout << "1.oldal: ";
	cin >> a;
	cout << "2.oldal: ";
	cin >> b;
	cout << "3.oldal: ";
	cin >> c;

	cout << "A haromszog oldalai: " << a << vesszo << szokoz << b << vesszo << szokoz << c << "\n";


	bool szekhet = false;

	if ((a + b > c) and(a + c > b) and(b + c > a));

}
Last edited on
It literally has zero affect when you include that in c++ since they are part of the standard.


What compiler are you using?
This is the <ciso646> header:

1
2
3
4
5
6
7
8
9
10
11
12
13
// ciso646 standard header
#pragma once
#ifndef _CISO646_
#define _CISO646_
#include <yvals.h>

#include <iso646.h>/
#endif /* _CISO646_ */

/*
 * Copyright (c) 1992-2012 by P.J. Plauger.  ALL RIGHTS RESERVED.
 * Consult your license regarding permissions and restrictions.
V6.00:0009 */


This is the iso646.h:

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
/* iso646.h standard header */
#pragma once
#ifndef _ISO646
#define _ISO646
#ifndef RC_INVOKED

 #if !defined(__cplusplus) || defined(_MSC_EXTENSIONS)
  #define and	&&
  #define and_eq	&=
  #define bitand	&
  #define bitor	|
  #define compl	~
  #define not	!
  #define not_eq	!=
  #define or		||
  #define or_eq	|=
  #define xor	^
  #define xor_eq	^=
 #endif /* !defined(__cplusplus) || defined(_MSC_EXTENSIONS) */
#endif /* RC_INVOKED */
#endif /* _ISO646 */

/*
 * Copyright (c) 1992-2012 by P.J. Plauger.  ALL RIGHTS RESERVED.
 * Consult your license regarding permissions and restrictions.
V6.00:0009 */



Its a simple #define statement, i.e:

#define and &&
Last edited on
What compiler are you using?
g++/clang
http://coliru.stacked-crooked.com/a/6916c61af9a63ab9

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>

int main()
{
    std::cout << "Hello, world!" << std::endl;
    
    if(true and true)
    {
        //nothing useful
    }
    
    return 0;
}
g++ -std=c++11 -O2 -Wall -pedantic main.cpp && ./a.out
clang++ -stdlib=libc++ -std=c++11 -O2 -Wall -pedantic main.cpp && ./a.out
Hello, world!
Hello, world!


Visual studio is probably not conforming to the standard and makes you include the header that shouldn't do anything in c++.
Last edited on
But that header or

#define and &&


should fix the problem the person was having.

Using "&&" would fix it as well.
But that header or

#define and &&
Sure, he can do that if he is using visual studio since it does not conform to the standard. If you use any other compiler you are going to get errors when you try to use that define.

http://coliru.stacked-crooked.com/a/f886071a0cdab8e1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>

#define and &&

int main()
{
    std::cout << "Hello, world!" << std::endl;
    
    if(true and true)
    {
        //nothing useful
    }
    
    return 0;
}
g++ -std=c++11 -O2 -Wall -pedantic main.cpp && ./a.out
clang++ -stdlib=libc++ -std=c++11 -O2 -Wall -pedantic main.cpp && ./a.out
main.cpp:3:9: error: "and" cannot be used as a macro name as it is an operator in C++
 #define and &&
         ^
main.cpp:3:9: error: C++ operator 'and' (aka '&&') used as a macro name
#define and &&

Though it is rarely used in C++, you can actually use "and" to mean the logical AND operator.


i never heard about it 'till now
Sure, he can do that if he is using visual studio since it does not conform to the standard. If you use any other compiler you are going to get errors when you try to use that define.


But he was getting an error so his compiler ( Visual Studio or not) doesn't support the standard completely. The fix is to simply #define it or include the header. I suspect a compile that does support the C++ 11 stadard completely wouldn't have the iso646 header since all it does is define the words for the logical and bit operands. I imagine Visual studio doesn't support that because it would break some internals, and the work around is the header.
Pages: 12