Hi njrobby,
You a few things going on here - the first one is to please always use code tags, Select your code then press the <> button on the right.
using namespace std;
This brings in the whole std namespace which is huge, into the global namespace which can cause lots of conflicts with variable & function names. For example there is a
std::left
, if you had a function with that name you have a conflict.
To fix this, put
std::
before each std thing as in
std::cout
,
std::cin
,
std::endl
,
std::vector
,
std::string
etc.
This code:
const double G=6.673*pow(10.0,-11.0);
should be written:
const double G=6.673e-11.0
All doubles & floats can take this exponent format.
double m1=0.0,m2=0.0,D=0.0,r1=0.0,r2=0.0,F=0.0,inc=0.0;
It is good practice to declare & initialise each variable on it's own line, so you can comment them - explain what each variable means and any valid ranges etc.
while (done==false){
while (!done){
!
is the not operator - it reverses logic.
Although I reckon you might not need the
done
variable at all, and this code which is repeated 5 times could be reorganized into a function:
1 2 3 4 5 6 7 8 9 10 11
|
while (done==false){
cout<<"Enter the mass of planet #1 in kg: ";
cin>>m1;
if(cin.fail()==0){
done=true;}
else{
cout<<"Huh? Type a number genius.. You know, 1 or 2 or 10...\n";
cin.clear();
cin.ignore(256,'\n');
}
}
|
The above code sets done to true the first time, causing all the rest to be skipped, this is the crux of your problem.
F=((m1*m2)/pow((curDist+r1+r2),2.0))*G;
With this, this pow function uses a series to calc the value, and it is very expensive operation to square a value. So invent a new variable and multiply it by itself.
Hope all goes well :+)