What am I doing wrong

I can't seem to find what is giving me errors. Any help will be appreciated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
(Header.h)
#ifndef CONSTANTS_H
#define CONSTANTS_H

namespace constants
{
	int x;
	int radius(x);
	constexpr double pi(3.14159);
	constexpr double avogadro(6.0221413e23);
	constexpr double my_gravity(9.2);
}
#endif
(source code)
#include <iostream>
#include "Header.h"

using namespace constants;
using namespace std;
int main()
{
	int radius(x);
	double circumference = 2 * radius * pi;
	cout << "What is the radius of that dang circle you want to know if you have enough gas money to go round trip? ";
	cin >> x;
	cout << "The dang route you need to take is " << circumference << " long." << endl;
	cin.ignore();
	cin.ignore();

	return 0;
}


Don't put what are essentially local variables in your constants namespace.
I'm not sure what you think int radius(x) is doing. x is uninitialized, remember.

Then you put a calculation of circumference before you read in the radius (actually you read in x and seem to expect that to influence radius that then goes back in time and calculates circumference, or maybe you're thinking the calculations work like on a spreadsheet?).

It should be more like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#ifndef CONSTANTS_H
#define CONSTANTS_H
namespace constants {
	constexpr double pi{3.14159};
	constexpr double avogadro{6.0221413e23};
	constexpr double my_gravity{9.2};
}
#endif

#include <iostream>
#include "Header.h"
using namespace constants;
using namespace std;

int main() {
	cout << "Circle radius: ";
	int radius = 0;
	cin >> radius;
	double circumference = 2 * radius * pi;
	cout << "Circumference: " << circumference << '\n';
	return 0;
}

Topic archived. No new replies allowed.