Home > Back-end >  how do i make a namespace for math formula
how do i make a namespace for math formula

Time:12-02

[I want to calculate the space of the circle but after i enter the value of r the value of x become 0]

(https://i.stack.imgur.com/BjgpH.png) (https://i.stack.imgur.com/LaRWI.png)

I did not try anything since I am a beginner

CodePudding user response:

This is not the proper usage to namespace. We use such language feature in case we want to generate a space with our own functions and variables, similar to classes. I recommend you to create a function with desired behaviour.

CodePudding user response:

you are not returning anything in your namespace.. check this code:

// Creating namespaces
#include <iostream>
using namespace std;

namespace mc {
const float b = 3.14;
float value(int r) { 
    return b*r*r; 
    }
}
 
int main()
{
    int r;
    cin>>r;
    cout << mc::value(2) << '\n';
    return 0;
}

Please mark this answer correct if you are satisfied with this.

  • Related