Array Problem
-
Hi, im trying to use the specific value of an array in a computation in another function; but don't know how to set it up. In test(), i want to use the 6th value of C[] in the computation. How do i set this up please?
#include "stdafx.h" #include const int size = 10; double A[size] = {0},B[size] = {0}, C[size],c,d; double PI = 3.141592653589793238462643383279502884197; void rah(double C[]) { for (int i=0;i
-
Hi, im trying to use the specific value of an array in a computation in another function; but don't know how to set it up. In test(), i want to use the 6th value of C[] in the computation. How do i set this up please?
#include "stdafx.h" #include const int size = 10; double A[size] = {0},B[size] = {0}, C[size],c,d; double PI = 3.141592653589793238462643383279502884197; void rah(double C[]) { for (int i=0;i
i am not clear abt ur requirement. try this #include #include const int size = 10; double A[size] = {0},B[size] = {0}, C[size],c,d; double PI = 3.141592653589793238462643383279502884197; double rah(double *C) { int i = C-::C ; A[i] = sqrt(10*i); B[i] = 2*PI*i; ::C[i] = A[i]*B[i]; return ::C[i] ; } double test()//how do i write this correctly? { d = PI * rah(&C[5]); return d ; } int main(int argc, char* argv[]) { printf("Hello World!\n %f", test()); return 0; } naren VC++ programmer
-
Hi, im trying to use the specific value of an array in a computation in another function; but don't know how to set it up. In test(), i want to use the 6th value of C[] in the computation. How do i set this up please?
#include "stdafx.h" #include const int size = 10; double A[size] = {0},B[size] = {0}, C[size],c,d; double PI = 3.141592653589793238462643383279502884197; void rah(double C[]) { for (int i=0;i
aaadetos wrote: In test(), i want to use the 6th value of C[] in the computation. How do i set this up please? double test()//how do i write this correctly? { rah(C); d = PI * rah(C[5]); } It appears that you are already using "the 6th value of C[] in the computation." What is it that you think is wrong? The code that I do see as wrong is when you are calling the
rah()
function.rah()
is expecting adouble
array (i.e.,C[]
), yet you are calling it with a singledouble
value (i.e.,C[5]
).
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
-
aaadetos wrote: In test(), i want to use the 6th value of C[] in the computation. How do i set this up please? double test()//how do i write this correctly? { rah(C); d = PI * rah(C[5]); } It appears that you are already using "the 6th value of C[] in the computation." What is it that you think is wrong? The code that I do see as wrong is when you are calling the
rah()
function.rah()
is expecting adouble
array (i.e.,C[]
), yet you are calling it with a singledouble
value (i.e.,C[5]
).
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
-
Thanks a lot guys. The dilemma was to use one of the elements (the 6th) in the computation. I implemented test() in the following way:
double test() { rah(C); d = PI * C[5]; return d; }
Why is
d
a global variable? Unless absolutely necesssary, that is very poor practice. In this instance, it makes no sense fortest()
to returnd
since it is already global. Either maked
local to thetest()
function, or changetest()
to return nothing.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown