Hey guys I'm new to the variables in C++ I use TurboC++ program. If you could, please help me get rid of this one error that keeps popping up... It says "Declaration terminated incorrectly" and when I click on the error it tells me its the "{" at the beginning
Anyone know whats wrong?
Thanks

#include <iostream.h>
 
{
    cout << "Hey." << endl;
    cout << "Look what I made."
 
#include <iostream.h>
void main()
//math
    int x,y; //declare two integer variables, x and y
    x=20; //set x to 20
    y=10; //set y to 10
    x=x+0; //add 1 to x
    y=y*2; //divide y by 2
    cout << "x equals: " << x << " and y equals: " << y << endl;
}

To be honest I don't know anything about C++, but I know this much

x=x+0; //add 1 to x

This is not adding 1, you add 1in this way x++; or x = x + 1; or x += 1;

y=y*2; //divide y by 2

and this is not dividing neither.

Concernig your original error take another look at the first "{"

It should be after the
int main()
{
}
in fact this portion

#include <iostream.h>
void main()

should be before anything else

First of all, use code tags. It makes code much easier to read (more info in my signature.)

Don't use iostream.h, as it's outdated. void main should be avoided at all costs (see my signature also).

You should use a proper compiler instead of Turbo that doesn't compile such bad coding practices as I have mentioned above. Several easy-to-use compiler are Dev-C++ and Code::Blocks. If you need a more advanced environment, feel free to download the express version of Visual Studio 2005.

This is incorrect:

{
    cout << "Hey." << endl;
    cout << "Look what I made."

Remove the brace that I highlighted in red, and paste the rest of this code down below the main() statement.

The variable assignments are incorrect as previously stated.

x=x+0; //add 1 to x
    y=y*2; //divide y by 2

I suggest reading up on this:
http://www.cprogramming.com/tutorial/lesson1.html

Also note that you can use +=, *=, /= etc, to be shortcuts for x = x + something, x = x * something, etc respectively. But for now stick to what it outlines in the tutorial I posted, and you should be fine.

First of all, use code tags. It makes code much easier to read (more info in my signature.)

Yes, please

Don't use iostream.h, as it's outdated. void main should be avoided at all costs (see my signature also).

Absolutely agree

You should use a proper compiler instead of Turbo that doesn't compile such bad coding practices as I have mentioned above.

Most people here frown on Turbo simply because it's old. Most current compilers allow the same bad coding practices (esp those listed above) as Turbo, so upgrading for that reason is not necessary. The only reason to change IMAO is you want to use the power of your 32bit processor. The compilers sited are good for this. If all you are doing is learning how the language works, most compilers (including Turbo) will do the trick just fine.

Now, to analyze your code in place. Basically just reiterating what's already been said but with the code intact:

#include <iostream.h>

{   // this { starts a block, but there's nowhere for the block 
    // to live.  This needs to be in a function -- like main()
    cout << "Hey." << endl;      // These can't be here, either
    cout << "Look what I made."  // they also must be in a function

#include <iostream.h>    // why twice?
void main()
//math
    // here's where that { must go
    int x,y; //declare two integer variables, x and y
    x=20; //set x to 20
    y=10; //set y to 10
    x=x+0; //add 1 to x
    y=y*2; //divide y by 2
    cout << "x equals: " << x << " and y equals: " << y << endl;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.