1. ## averaging

I am trying to calculate the average of the numbers the user entered but I can't figure out how many numbers the user actually entered to so I can divide by the sum. The user can enter up to 10 numbers or a zero to exit at anytime. I need to be able to calculate the average but not include zero.

Code:
```#include <stdio.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

int main(void)
{
char theNums[10][50];
int nums[10];
int i, j, sum = 0;
int average, qty;

printf("Start by entering up to 10 numbers.  To exit enter a zero.\n");
printf("\n");

for(i=0; i < 10; i++)
{
printf("Enter a Number: ");
fgets(theNums[i], 50, stdin);

j = strlen(theNums[i])-1;

theNums[i][j] = '\0'; /* get rid of '\n' */

if(theNums[i][0] == '0')
break;
else if(!isdigit(theNums[i][0]))
{
printf("%s is not a valid entry.\n", theNums[i]);
nums[i] = 0;
}
else
nums[i] = atoi(theNums[i]);
}

printf("\n\n");

for(j=0; j < i; j++)
sum+=nums[j];
average = (sum/qty);

printf("The sum of your numbers is %d", sum);
printf("\n");

printf("The average of the numbers is %d", average);
printf("\n")

getchar(); /*wait for keystroke before exiting*/

return 0;
}```

2. make another variable

int numberCount = 0;

numberCount++;

3. OK, I have the sum and average working. I am trying to display what the user entered for numbers and also sort them. Can someone let me know what I am doing wrong.

Code:
```#include <stdio.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

int main(void)
{
char theNums[10][50];
int nums[10];
int i, j, sum = 0;
float average;
int numberCount = 0;

printf("Start by entering up to 10 numbers.  To exit enter a zero.\n");
printf("\n");

for(i=0; i < 10; i++)
{
printf("Enter a Number: "); /*get the numbers*/
fgets(theNums[i], 50, stdin);

j = strlen(theNums[i])-1;

theNums[i][j] = '\0'; /* get rid of '\n' */

if(theNums[i][0] == '0') /* exit if zero */
break;
else if(!isdigit(theNums[i][0])) /*verify user data is a digit*/
{
printf("%s is not a valid entry.\n", theNums[i]);
nums[i] = 0;
}
else
nums[i] = atoi(theNums[i]);
numberCount ++;	/*count the numbers being entered*/
}

printf("\n\n");

average = 0; /*calculate average*/
for(j=0; j < i; j++)
sum+=nums[j];
average = (sum/numberCount);

printf("Here are the numbers you entered:\n"); /*what am i doing wrong here*/
for (++i;i>=0; ++i)
printf("%d ",theNums[i]);
printf("\n");

printf("Here are the numbers you entered sorted from lowest to highest:\n"); /*what am i doing wrong here*/
for (++i;i>=0; ++i)
printf("%d ",theNums[i]);
printf("\n");

printf("The sum of your numbers is %d", sum); /* display sum*/
printf("\n");

printf("You have entered %d numbers", numberCount); /*display qty of numbers entered*/
printf("\n");

printf("The average of the numbers is %.1f", average); /*display average*/
printf("\n");

getchar();

return 0;
}```

4. Look at your first 'for' loop
Code:
`for(i=0; i < 10; i++)`
Now look at your second one
Code:
`for (++i;i>=0; ++i)`
for (where to start; loop while this is true; increment)

Maybe you want to...
Start at 0? keep counting all the numbers that have been entered? increment by 1 after each loop?

Something along the lines of (but maybe not exactly)
Code:
`for (i=0;i < numberCount;i++)`
Also, if you need to sort, then you actually need some sort of sorting code.

5. I made some more changes but still I am having a problem displaying the number enetered and sorted.

Code:
```#include <stdio.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

int main(void)
{
char theNums[10][50];
int nums[10];
int i, j, sum = 0, average;
int numberCount = 0;

printf("Start by entering up to 10 numbers.  To exit enter a zero.\n");
printf("\n");

for(i=0; i < 10; i++)
{
printf("Enter a Number: "); /*get the numbers*/
fgets(theNums[i], 50, stdin);

j = strlen(theNums[i])-1;

theNums[i][j] = '\0'; /* get rid of '\n' */

if(theNums[i][0] == '0') /* exit if zero */
break;
else if(!isdigit(theNums[i][0])) /*verify user data is a digit*/
{
printf("%s is not a valid entry.\n", theNums[i]);
nums[i] = 0;
}
else
nums[i] = atoi(theNums[i]);
numberCount ++;	/*count the numbers being entered*/
}

printf("\n\n");

average = 0; /*calculate average*/
for(j=0; j < i; j++)
sum+=nums[j];
average = (sum/numberCount);

printf("Here are the numbers you entered:\n"); /*what am i doing wrong here*/
for(i=0; i < 10; i++)
printf("%d ",theNums[i]);
printf("\n");

printf("Here are the numbers you entered sorted from lowest to highest:\n"); /*what am i doing wrong here*/
for(i=0; i < 10; i++)
printf("%d ",theNums[i]);
printf("\n");

printf("The sum of your numbers is %d", sum); /* display sum*/
printf("\n");

printf("You have entered %d numbers", numberCount); /*display qty of numbers entered*/
printf("\n");

printf("The average of the numbers is %.1f", average); /*display average*/
printf("\n");

getchar();

return 0;
}```

6. I can't compile your code where I am, and I'm not good enough to see all your issues just from your code. It would be helpful if you told us what was going wrong (i.e. what the output is and how it is wrong). Also, you need to learn about sorting, do a search on the board, you will probably find a 'bubble sort' fairly easy to grasp and it should suit what you want to do.

7. it doesnt print the numbers the user entered. I must have some bug in there but can't figure out what is it.

8. I'm not sure what you doing within the for loop, so here's something that might help you.

This program asks the user for 2 numbers, one at a time, stores their input in a char array, and converts that to an int in an int array.

No error checking done, this is for demo purposed only
Code:
```#include <stdio.h>
#include <stdlib.h>

int main(void)
{
char theNums[2][50];
int  Nums[2];
int  i;

for (i = 0; i < 2; i++)
{
printf ("Enter a number: ");
fgets(theNums[i], 50, stdin);
printf ("You entered %s", theNums[i]);
Nums[i] = strtol(theNums[i], NULL, 10);
printf ("Thats number %d\n", Nums[i]);
}

return(0);
}```