Homework Lab Help

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?

#pragma intrinsic(sqrt)
#include <iostream>
#include <math.h>
#include <cmath>

using namespace std;

const float G = 6.674e-011;//0.00000000006674;
const float M = 5.974e+024;//5974000000000000000000000.0;
float g1 = 9.792;
float g2 = 9.803;
float height = 0.0;

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;
}
You're trying to get the square root of a negative number. How your friend got a non-NaN out of this code, I don't know.
oh dang!
Haha awesome

Another question...

on the Height = sqrt ((G* M*((1/g2)-(1/g1))));

line

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.
btw me and my friend we both had float g1 and float g2 switched. Thanks!
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'.
how would i get the squareroot of G*M
like this?
sqrt(G*M)

whats a dereference operator?
Topic archived. No new replies allowed.