The problem is as follows:(adsbygoogle = window.adsbygoogle || []).push({});

Design and build a program that does the following:

a. Declare a 100-element array that will hold float values.

b. In a subprogram set each element of the array to a random float value from 1 to 10;

i. Use the rand () function and the stdlib.h include file;

c. Declare two float variables to hold the max and min value of the array

d. Make a sub program that will accept the array and the two variable as arguments

i. The subprogram will search the array and find the max value and place in the max variable.

ii. The subprogram will find the min value and place it the min variable.

e. Calculate the average of the max. and min. then make sub program to use the value as follows:

i. The subprogram will use the random array and the average value to determine the number of values of above the average value and the number of values below the average value.

ii. The subprogram shall be designed in such a way as not to be able to change the value of the average value.

f. In the main function output the statistics:

i. The range of values in the array

ii. The mid point of the array

iii. The number of values above and below the mid point

This compiles but has an error when I run it. I'm still new at programming and, well, I've tried to tinker around with it but to no avail. Any insight as to what might be wrong?

This is my code:Code (Text):

#include <StdAfx.h>

#include <iostream>

#include <math.h>

#include <iomanip>

#include <cstdlib>

using namespace std;

void randomizer(float*);

void locate(float*,float*,float*);

void calculate(float*,float*,float*,float*,int*,int*);

int main()

{

float random[100], *max, *min, *avg;

int *abovecounter, *belowcounter;

randomizer(random);

locate(max,min,random);

calculate(max,min,random,avg,abovecounter,belowcounter);

cout << "The range of values is: "<< max<< " - "<<min<<" = "<<max-min<<endl;

cout << "The mid point of the values is: " << avg << endl;

cout << "The number of values above the mid point is: "<<abovecounter<<endl;

cout << "The number of values below the mid point is: "<<belowcounter<<endl;

return 0;

}

void randomizer(float *random)

{

for(int index =0; index<=100; index++)

{

random[index] = ((rand()/RAND_MAX)*9+1);

}

}

void locate(float *max,float *min, float* random)

{

*max=random[0];

*min=random[0];

for(int index = 0; index<=100; index++)

{

if(random[index]>*max)

{

*max=random[index];

}

if(random[index]<*min)

{

*min=random[index];

}

}

}

void calculate(float*max, float*min, float*random, float*avg, int*abovecounter, int*belowcounter)

{

*avg = ((*max+*min)/2);

for(int index=0; index<=100; index++)

{

if(random[index]>*avg)

{

belowcounter = belowcounter +1;

}

if(random[index]<*avg)

{

abovecounter = abovecounter +1;

}

}

}

**Physics Forums | Science Articles, Homework Help, Discussion**

Dismiss Notice

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# C++ question

**Physics Forums | Science Articles, Homework Help, Discussion**