Hi, Ive made a little program that calculates the area of a circle by doing Pi * r2, but its not working and I don't know why:

#include <iostream>
using namespace std;

#define PI 3.14159265358979323846
#define NEWLINE '\n'

int main ()
{
  float Radius = 0;
  cout << "Radius: ";
  cin >> Radius;

  circle = Radius * Radius * PI;
  cout << circle;
  cout << NEWLINE;
  // End Program
  char StopCharacter;
  cout << "Press any key to Terminate";
  cin >> StopCharacter;
  
  return 0;
}

Any help would be appreciated

Member Avatar for iamthwee

And what does your compile log say?

I have added some more code to the program:

#include <iostream>
using namespace std;

#define PI 3.14159265358979323846
#define NEWLINE '\n'

int main ()
{
  int Radius, Circle, ReturnCode;
  
  ReturnCode = 0;
  
  Radius = 0;
  cout << "Radius: ";
  cin >> Radius;

if(!cin.fail())
{
  Circle = Radius * Radius * PI;
  cout << Circle << endl;
  cout << NEWLINE;
  // End Program
}
else
{
  cerr << "Thats not a number"; << endl;
  
  cin.clear();
  char BadInput[20];
  cin >> BadInput;
  
  ReturnCode = 1;
  
};
  
  char StopCharacter;
  cout << endl << "Press any key to Terminate";
  cin >> StopCharacter;
  
  return ReturnCode;
}

Here is a screen shot of my compile log:

http://img232.imageshack.us/img232/4169/09142008160400ja5.png

But, I still don't know what I need to do to correct this.

Member Avatar for iamthwee

> int Radius, Circle, ReturnCode;

Should that be declared as a double instead of an int?

> cerr << "Thats not a number"; << endl;

What's that semicolon doing before the <<endl?


> };

Why is there a semicolon after the closing curly bracket?

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.