Adventure Game Studio

Community => General Discussion => Topic started by: Theme on Fri 13/01/2006 20:42:53

Title: programming help (not ags)
Post by: Theme on Fri 13/01/2006 20:42:53
I have this function

void DadosDeCirculo(double *raio) {
     
     printf("\nDigite o raio do circulo: ");
     scanf("%f",&raio);
     
};

but the scanf is not working. I tried with *raio, raio, &(*raio) and *(&raio) but it keeps on value 0
pls help

o/
Title: Re: programming help (not ags)
Post by: DoorKnobHandle on Fri 13/01/2006 20:57:39
You might want to say which programming language it is. It looks exactly like c++ except you end the function definition with a }; ?

If you use c++, you should look into the iostream.h header, which gives you overloaded operators, that work like this:


cout << "This is a test output";
int number;
cin >> number;


That would output the message and then let the user enter a number.
Title: Re: programming help (not ags)
Post by: Theme on Fri 13/01/2006 21:02:47
sorry, I'm using C only

o/
Title: Re: programming help (not ags)
Post by: scotch on Fri 13/01/2006 21:22:47
The main problem is you are using a float format string to try and fill a double value (a double is a double precision float, a different type to float).  What you want is:

void DadosDeCirculo(double *raio) {
     printf("\nDigite o raio do circulo: ");
     scanf("%lf",raio);
};
The "l" prefix on type like that means "long" so "li" means "long int", but paired with "f" it means a double.
Also note that I took the & off the raio in the scanf, this is because a pointer is passed in, and you want to fill the memory that the pointer points to, not the memory that the pointer is located at, that would be a big mistake.
Title: Re: programming help (not ags)
Post by: Theme on Fri 13/01/2006 21:26:13
thanks scotch
love you :**

o/