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
#define radius

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;
}

Recommended Answers

All 2 Replies

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.

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

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.