-
Code:
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
void GetValues(int x[], int *pN);
int FindBig(int x[], int n);
int FindSml(int x[], int n);
float FindAvg(int x[], int n);
void main()
{
int a[100], myBig, mySml, n;
float myAvg;
GetValues(a,&n);
myBig=FindBig(a,n);
mySml=FindSml(a,n);
myAvg=FindAvg(a,n);
printf("The largest value is: %d\n",myBig);
printf("The smallest value is: %d\n",mySml);
printf("The average value is: %.2f\n",myAvg);
}
void GetValues(int x[], int *pN)
{
// Get user input for number of values here.
printf("Enter Number Of Values: ");
scanf("%d",&*pN);
// insure it is less than 100
for(*pN=1; *pN=100; pN++)
{
printf("Enter Value: ");
scanf("%d",&*pN);
}
}
int FindBig(int x[], int n)
{
int myBig;
myBig = x[0];
if(x[n]>myBig)
{
myBig = x[n];
return myBig;
}
return 0;
}
int FindSml(int x[], int n)
{
int mySml;
mySml = x[0];
if(x[n]<mySml)
{
mySml = x[n];
return mySml;
}
return 0;
}
float FindAvg(int x[], int n)
{
{
float sum,*pN, myAvg;
sum = 0;
sum+=x[n];
myAvg=(float)((float)sum / *pN);
return myAvg;
}
return 0;
}
-
it should only be prints the second print statement as many times as the users number of values
-
What do you think this line of code is doing? Please try to explain it clearly.
Code:
for(*pN=1; *pN=100; pN++)
Jim
-
oops, Im not sure how I would word it so it only prints the statment as many times as the user inputs
its taking the value given by the user setting it to one
then printing the statement untill the user inputs something higher than 100
and then adds 1 to PN everytime
-
But shouldn't you be doing this for the number of times the user is asking for?
The loop should look like:
Code:
for(i = 0; i < *pN; i++)
This way if the user says they want 10 values it will ask for 10 values.
Also you should be filling in your array with the scanf not changing *pN.
Jim
-
Okay thank You Im getting a run time error, but i gtg to bed thank you for the help