Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array problem

Status
Not open for further replies.

aaadetos

Programmer
Nov 21, 2004
54
0
0
US
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?
Code:
#include "stdafx.h"
#include <cmath>

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<size;i++)
	{
		A[i] = sqrt(10*i);
		B[i] = 2*PI*i;
		C[i] = A[i]*B[i];
	}
}

double test()//how do i write this correctly?
{
	rah(C);
	d = PI * rah(C[5]);

}


int main(int argc, char* argv[])
{
	test();
//	printf("Hello World!\n");
	return 0;
}
 
Hi,

I'm not clear exaclty what you want to do?

I've put some code below as a "guess" as to what your trying to do? and a couple of suggestions?

Code:
PI = 4*ATAN(1.0)

double rah ( int value )
{
  A[value] = sqrt(10*value);
  B[value] = 2*PI*value;
  C[value] = A[value]*B[value];
  return ( C[value] );
}

double test()
{
  double yourValue;
  //.....do your calcs.....
  yourValue = PI * rah( 2 );
  return ( yourValue );
}

Robert Cumming
 
please explain what you need a little more clearly.

also, your code will not compile as is.. because your test function is declared so that it returns a double. you do not return anything.

another issue is that you declare:
void rah(double C[])
btu you pass only a double and not an arrya of doubles...

i would suggest you use pointers!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top