-8

I am trying to write a C++ program that prompts the user for the radius of a circle then calls inline function circleArea() to calculate the area of that circle

#include <stdio.h>
#include <iostream>
#include <math.h>
using namespace std;

class Circle {
  private:
    float radius;

  public:
    inline void circleArea(float)

    void input() {
      cout<<"\nEnter the radius of circle";
      cin>>radius;
    }

    Circle() {
      float radius=0.0;
    }
};

void circleArea()
{
  float a,r;
  a=(3.14*r*r);
}

int main()
{
  Circle c;
  c.input();
  c.circleArea();
}

Here i don't understand how to put inline function, and i am not getting any output, my output shows blank space after putting the value of radius.

Bill Lynch
  • 80,138
  • 16
  • 128
  • 173
stayfrosty
  • 1
  • 2
  • 2
  • 3
  • Try in `main` to use `cout << c.circleArea() << endl` or something similar. The code is generally problematic. You might want to read some C++ or design book. – Ami Tavory Mar 13 '16 at 18:06
  • 4
    Compile time error is what you should be getting... – LogicStuff Mar 13 '16 at 18:07
  • I have no idea why there is a class in this code *at all*. – WhozCraig Mar 13 '16 at 18:07
  • You need to get functions working at all before worrying about *inline*. Get a good book and work methodically through that, a couple of hours every day: https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list – Galik Mar 13 '16 at 18:19

1 Answers1

0

void circleArea should be void Circle::circleArea. As written it's not a member function. Once that's done, note that a is a local variable in the function; when the function returns, the value of a is gone.

To make circleArea inline, mark it inline at the point where it's defined. But that's an issue for the future.

Pete Becker
  • 74,985
  • 8
  • 76
  • 165