Discussion:
Simple CPP program does not compile!!
(too old to reply)
Sheila
2007-11-04 22:35:23 UTC
Permalink
I corrected one error (else cout << Invalid input" << endl; changed to
else cout << "Invalid input" << endl;) but there are still three errors
as follows:

C:\TC\DATA>bcc32 totals.cpp
Borland C++ 5.82 for Win32 Copyright (c) 1993, 2005 Borland
TOTALS.CPP:
Error E2451 TOTALS.CPP 7: Undefined symbol 'not' in function main()
Error E2377 TOTALS.CPP 7: While statement missing ) in function main()
Error E2054 TOTALS.CPP 17: Misplaced else in function main()
Warning W8004 TOTALS.CPP 18: 'total' is assigned a value that is never
used in f
unction main()
*** 3 errors in Compile ***

Thank you
I have just written a simple CPP program but it does not compile using
// *****************************************************************************
#include <iostream>
using namespace std;
int main()
{
bool finished = false;
int total = 0;
while (not finished)
{
int num;
cin >> num;
if (cin.fail())
finished = true;
else total = total + num;
}
if (cin.eof())
cout << "Total is " << total << endl;
else cout << Invalid input" << endl;
}
// *****************************************************************************
Any ideas what could be the problem? I have managed to test my
installation by typing a simple hello, world program but this particular
one does not work!!
David Dean [CodeGear]
2007-11-05 02:17:16 UTC
Permalink
while (not finished)
You must enable alternate tokens in the project options for this
syntax to compile.
--
-David
Bob Gonder
2007-11-05 02:51:33 UTC
Permalink
Post by David Dean [CodeGear]
while (not finished)
You must enable alternate tokens in the project options for this
syntax to compile.
Or use
while( ! finished )
Sheila
2007-11-05 20:44:21 UTC
Permalink
Thank you to both David and Bob. I used (! finished) and it compiled.
Also, I found that (using M$ VC++ Express Ediion) one can use an
additional include file like this:

#include <iso646.h>

and to change this:

while (not (finished))

This is because "not" is a function (apparently) in iso/c++ and so
"finished" should be a parameter i.e. its own brackets.

Kind regards,
Post by Bob Gonder
Post by David Dean [CodeGear]
while (not finished)
You must enable alternate tokens in the project options for this
syntax to compile.
Or use
while( ! finished )
Alan Bellingham
2007-11-05 21:05:37 UTC
Permalink
Post by Sheila
Thank you to both David and Bob. I used (! finished) and it compiled.
Also, I found that (using M$ VC++ Express Ediion) one can use an
#include <iso646.h>
Yes, it may be done using that header file ...
Post by Sheila
while (not (finished))
Actually, the (inner) brackets *are* unnecessary.
Post by Sheila
This is because "not" is a function (apparently) in iso/c++ and so
"finished" should be a parameter i.e. its own brackets.
The VC++ include file merely contains some definitions. That for 'not'
is as follows:

#define not !

The result of the preprocessor is to turn

while (not finished)

into

while (! finished)

The brackets you use aren't harmful, and for a longer expression they
may be appropriate, but 'not' is not a function, it's an operator, and
no more *needs* the brackets than other operators like '+' do.

Alan Bellingham
--
Team Browns
<url:http://www.borland.com/newsgroups/> Borland newsgroup descriptions
<url:http://www.borland.com/newsgroups/netiquette.html> netiquette
Loading...