Click to See Complete Forum and Search --> : in serious need of help


Larry Flynt
April 2nd, 2002, 03:51 PM
array creation...

simple attempt to impress a lady backfires. she asked if i could do it, course i said,but then promptly forgot to do it, now she needs it and im buggered!!! as i dont know how to do this in c++, but hey she needn't know eh?

ok, need to process a set of numerical values stored in an array.these values will be entered by user at run time. can enter any amount up to 50.
must calculate the following
a)count of numbers input
b)max and min of input values
c)range
d)mean value
e)median

just something quick and simple that works... as i cannot do it for the life of me...

cheers i'll let u know how i get on

Gvido
April 2nd, 2002, 07:44 PM
sample simple code:


...

#define MAX_SIZE 50 // maximum array size

// getting array size from user
int GetArraySize();
// function gets array from input
void GetArray(float *array, int size);
// getting range
float Range(float *array, int size);
// getting max value
float Max(float *array, int size);
...
// output program results
void Report(float *array, int size);

void main()
{
float array[MAX_SIZE];

int size = GetArraySize();
GetArray(array, size);
Report(array, size);
}

int GetArraySize()
{
int size = 0;
while(size < 0 || size > MAX_SIZE)
{
printf("Input array size: ");
scanf("%d", &size);
if(size > 0 && size < MAX_SIZE) break;
printf("\nWrong size.\n");
}

}

void GetArray(float *array, int size)
{
printf("\nInput array: ");
for(int i = 0; i < size; i++)
scanf("%f", array + i);
}

void Report(float *array, int size)
{
float range = Range(float *array, int size);
float max = Max(float *array, int size);
...
printf("Range: %f", range);
printf("Max: %f", max);
...
}

float Range(float *array, int size)
{
...
}

...

Larry Flynt
April 3rd, 2002, 12:09 PM
cheers mate, lets hope she can fill in the blanks