I was trying to create a really simple program to calculate the gravitational force between two objects in C++. So I wanted to declare a macro for G whose value is equal to 6.754*10^-11 and I used this:
#define G 6.754e-11.0;
But it generated a lot of stray errors as shown below:
cd '~/Desktop/CS/C++/Other PSETS'
g++ gravity.cpp -o gravity
Output:
gravity.cpp:5:28: error: stray ‘\342’ in program
#define G (6.754)*pow(10.0,��11.0);
^
gravity.cpp:10:52: note: in expansion of macro ‘G’
float gforce(float m1,float m2,float r){return G*m1*m2/(r*r);}
^
gravity.cpp:5:29: error: stray ‘\210’ in program
#define G (6.754)*pow(10.0,��11.0);
^
gravity.cpp:10:52: note: in expansion of macro ‘G’
float gforce(float m1,float m2,float r){return G*m1*m2/(r*r);}
^
gravity.cpp:5:30: error: stray ‘\222’ in program
#define G (6.754)*pow(10.0,�11.0);
^
gravity.cpp:10:52: note: in expansion of macro ‘G’
float gforce(float m1,float m2,float r){return G*m1*m2/(r*r);}
So, I decided to use the math library function cmath
for using pow()
, but still it wasn't of any use. What can I do to create such a macro?
Note: I am Using G++ on Ubuntu as shown below:
g++ --version
Output:
g++ (Ubuntu 7.2.0-8ubuntu3) 7.2.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.