Hello I am in a Physics C++ coding class. It has just started and i am still a noob at coding.
In the problem we must make a program to output the answer. I have declared teh variables and made the equation but when i compile it i do not get a number. I get
-1.#IND
I googled and found out that that means either infinite or a BIG number. My friend ran the same code on his computer (Visual Basic 2010 and im using the same) and got a number( like 340092 or something)
Can anyone tell me whats going on?
float calculateHeight(const float G, const float M, float g1, float g2)
{
float height = 0.0;
height = sqrt ((G*M((1/g2)-(1/g1)))); // Used G* M* cause it asked me to point at them.
return height;
}
void main ()
{
height = calculateHeight(G, M, g1, g2);
cout << "The Balloon is: " << height << endl;
}
I can not get the sqrt to work right. It wants me to point at G and M. I want to sqrt GM how would i go about doing that while Multiplying them? Or is that right.
I think you're confusing the multiplication operator (e.g. x*y) with the dereference operator (e.g. x+*y). They look the same, but they do entirely different things.
In C++ and most programming languages, you can't multiply things by just leaving them next to each other, as in mathematical notation. The compiler can't know that when you write "GM" you're talking about the product of G and M, and not a variable called 'GM'.