Hello all,
I am working on a project that will ask for data from a user and the program will eventually be menu driven, but currently is not. The data will give the number of items that are in a array, what the data is, the highest and the lowest numbers are and what their average are.
The MAX size of the array will be changed from the current 10 to 200. I need to be able to return what the actual number of cells of the array re being used so the program does not have to run through all 200. I added a printf statement in my main to confirm if I returned the value or not and it does not. In the function enter(), I have a printf to see if it will show the number found in arraySize. I typed in return arraySize, but this does not do it?
Suggestions?
CODE
#include <stdio.h>
#define MAX 10
int enter(int array[], int count);
void print(int array[], int size);
int counter(int array[], int size);
void large ( int array[], int size);
void small ( int array[], int size);
void average(int array[], int size);
int main()
{
int myarray[MAX];
int count;
int arraySize = 0;
printf("Enter one data item after each prompt\n");
printf("Press return after each one.\n");
printf("Signal with -1 when you are done with data input\n");
enter(myarray, MAX);
printf("\n");
printf( "Count again is %d\n:" , arraySize);
printf("\n");
printf("The numbers that are in the array are: ");
print(myarray, arraySize);
printf("\n");
counter(myarray, arraySize);
printf("\n");
average( myarray, arraySize);
printf("\n");
large ( myarray, arraySize);
printf("\n");
small ( myarray, arraySize);
printf("\n");
return 0;
}
/*******************functions*********************/
int enter(int array[], int count)
{
int i = 0;
int arraySize = 0;
while ( i < count && array[i] != -1)
{
i++;
arraySize++;
scanf("%d", &array[i] );
}
printf("Array size is :%d\n", arraySize);
return arraySize;
}
void print(int array[], int size)
{
int i;
for ( i = 0; i < size; i++)
printf("%d ", array[i] );
printf("\n");
}
/**************/
int counter(int array[], int size)
{
int i;
for (i=0; i < size; i++)
size++;
printf("The number of items that are in the array are/is %d\n", i);
}
void large ( int array[], int size)
{
int i;
int largest = array[0];
for ( i = 1; i < size; i++ )
{
if (array[i] > largest )
largest = array[i];
}
printf ( "Largest %d\n", largest );
}
void small ( int array[], int size)
{
int i;
int smallest = array[0];
for ( i = 1; i < size; i++ )
{
if (array[i] < smallest )
smallest = array[i];
}
printf ( "Smallest %d\n", smallest );
}
void average(int array[], int size)
{
int i;
int sum = 0;
int average = 0;
for ( i = 0; i < size; i++)
sum = sum + array[i];
average = sum / size;
printf("Average %d\n ", average);
}
Of course your help is greatly appreciated.
JC