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;

Edited 4 Years Ago by deceptikon: Changed to discussion thread

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 4 Years Ago 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.




Have a look at: setw

Edited 4 Years Ago by Lucaci Andrew

This article has been dead for over six months. Start a new discussion instead.