Groups > Borland > Borland C plus plus builder command line tools > Re: Simple CPP program does not compile!!




Re: Simple CPP program does not compile!!

Re: Simple CPP program does not compile!!
Sun, 04 Nov 2007 18:17:16 -080
In article <472E4026.1C6E17F2@NEWSGROUPS.COM>,
 Sheila <Sheila@borlands.com> wrote:

>   while (not finished)

   You must enable alternate tokens in the project options for this 
syntax to compile.
-- 
Post Reply
Re: Simple CPP program does not compile!!
Sun, 04 Nov 2007 18:51:33 -080
David Dean [CodeGear] wrote:
> Sheila  wrote:
>
>>   while (not finished)
>
>   You must enable alternate tokens in the project options for this 
>syntax to compile.

Or use
	while( ! finished )


Post Reply
Simple CPP program does not compile!!
Sun, 04 Nov 2007 21:56:54 +000
I have just written a simple CPP program but it does not compile using
free downloadable borland compiler (borland c++ 5.82 for Win 32).  The program
is here:

//
*****************************************************************************
#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!!
Post Reply
Re: Simple CPP program does not compile!!
Sun, 04 Nov 2007 22:35:23 +000
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


Sheila wrote:
> 
> I have just written a simple CPP program but it does not compile using
> free downloadable borland compiler (borland c++ 5.82 for Win 32).  The
program is here:
> 
> //
*****************************************************************************
> #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!!
Post Reply
Re: Simple CPP program does not compile!!
Mon, 05 Nov 2007 20:44:21 +000
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,


Bob Gonder wrote:
> 
> David Dean [CodeGear] wrote:
> > Sheila  wrote:
> >
> >>   while (not finished)
> >
> >   You must enable alternate tokens in the project options for this
> >syntax to compile.
> 
> Or use
>         while( ! finished )
Post Reply
<< Previous 1 2 Next >>
( Page 1 of 2 )
about | contact