I do not understand were I went wrong.

1st is this line:

(it is saying that this (;) Error: excepted an expression)

2nd is this line:

cout<<"\nRadius is " << radius << set(8)<< "PI is" <<PI;

something is wrong with the second (<<)

``````// Program illustrating the use if #defines

#include <iostream>
using namespace std;

#define PI 3.14159265

int main()
{
double circleArea;

// The area of a circle is PI * Radius * Radius

circleArea = PI * radius * radius;

cout<<"\nCircle Summary ";
cout<<"\nRadius is " << radius << set(8)<< "PI is" <<PI;
cout<<"\nThe circle's area is" << circleArea << "\n";

return 0;
}
``````

Edited by deceptikon: Changed to discussion thread

3
Contributors
2
Replies
4
Views
4 Years
Discussion Span
Last Post by Lucaci Andrew

First you have this:

``````#define radius
``````

Then this:

``````cout<<"\nRadius is " << radius << set(8)<< "PI is" <<PI;
``````

What exactly were you expecting to get printed when radius is replaced with nothing? The end result after preprocessing is this:

``````cout<<"\nRadius is " << << set(8)<< "PI is" <<PI;
``````

And that's obviously a syntax error. You have the same problem anywhere radius is used to mean anything except nothing.

Edited by deceptikon

as deceptikon pointed out:

``````#define radius
``````

Here you must give radius a value (as the point of this assignment illustrates: "Program illustrating the use if #defines"). `#defines` works as macros, here you gave `PI` a value which will be held throughout the entire program, thus doing the same with radius.
These are called pre-processeor directives: have a look at them: Click Here
If you try to change the value of radius for example, inside the program it will yeld an error.

``````set(8)
``````

it's

``````setw(8)
``````

Have a look at: setw

Edited by Lucaci Andrew

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.