Question: Write a program that reads integers from the keyboard until the user enters the sentinel value -999. The program should then print the minimum integer read, the maximum integer read and the average of all the integers. (Excluding the sentinel value -999)

I know how to post maxes & mins and set the sentinel value. I don't know how to tell the computer to sum up the values given and take the average since I need a generic function that would work for any number of values.

My code for everything else:

#include <stdio.h>

int main()
{

int num;
int min;
int max;
int avg;


printf("Enter a number (-999 to quit): ");
scanf("%d",&num);

//putting the first number the user entered in variable min and max
min = num;
max = num;


while(num!=-999)
{
if(num<min)
{
min = num;
}


if(num>max)
{
max = num;
}
printf("Enter another number (-999 to quit): ");
scanf("%d",&num);
}

printf("\nThe smallest number entered is %d\n",min);
printf("\nThe largest number entered is %d\n",max);



return 0;
}

Functions... how to pass value from one function to the next... using different methods

#include<stdio.h>

#include<conio.h>

void main()
{

int num;
int min;
int max;
int avg;
clrscr();

printf("Enter a number (-999 to quit): ");
scanf("%d",&num);

//putting the first number the user entered in variable min and max
min = num;
max = num;

while(num!=-999)
{
if(num<min)
{
min = num;
}

if(num>max)
{
max = num;
}
printf("Enter another number (-999 to quit): ");
scanf("%d",&num);
}

printf("\nThe smallest number entered is %d\n",min);
printf("\nThe largest number entered is %d\n",max);

getch();
}

The program has a good skeleton and observes many good practices such as declaring the variables before first use (or else it won't compile), initializing variables min and max after first scanf, etc.

To calculate the total and average, you need to:
add variables count and total.
Count should be set to one at the same time as max=num, total should be set to num at the same time.

Inside the while loop, increment count by one and increment total by num whenever num!=-999.

After the execution exits the loop, the total will represent the total of the numbers, and avg(should have been declared as float) can be calculated using:

avg=(float)(total)/count;

Give it a try and post what you've got. You should not be far from finishing it.

"Inside the while loop, increment count by one and increment total by num whenever num!=-999."

Where exactly inside the loop should I do this and how?
Do I say count++
to increment count by one, and do I say
total = total+num
inside the while loop to increment total and if so where?

This program runs but I can't get the correct mean average value:

int main()
{
//Variable declarations
int num;
int min;
int max;
float avg;
int count;
int total;


printf("Enter a number (-999 to quit): ");
scanf("%d",&num);


min = num;
max = num;
count = 1;
total = num;

until the user enters -999

while(num!=-999)
{
count++;
total = num;

if(num<min)
{
min = num;
}


if(num>max)
{
max = num;
}
avg = total/count;
printf("Enter another number (-999 to quit): ");
scanf("%d",&num);
}


printf("\nThe smallest number entered is %d\n",min);
printf("\nThe largest number entered is %d\n",max);
printf("\nThe mean average value is %f\n",avg);

//Exit program
return 0;
}

construct a C program that reads a positive three digit integer number and determine if the number satisfy the property or not.

Sure, here's a modified version of your code that calculates the sum of the integers entered and then calculates the average:

```
#include <stdio.h>

int main()
{
int num;
int min;
int max;
int sum = 0;
int count = 0;
float avg;

printf("Enter a number (-999 to quit): ");
scanf("%d", &num);

//putting the first number the user entered in variable min and max
min = num;
max = num;

while (num != -999)
{
if (num < min)
{
min = num;
}

if (num > max)
{
max = num;
}

sum += num; // add the current number to the sum
count++; // increment the count of numbers

printf("Enter another number (-999 to quit): ");
scanf("%d", &num);
}

if (count > 0) {
avg = (float) sum / count; // calculate the average
printf("\nThe smallest number entered is %d\n", min);
printf("The largest number entered is %d\n", max);
printf("The average of the numbers entered is %.2f\n", avg);
} else {
printf("No numbers were entered.\n");
}

return 0;
}
```

I hope this helps!

To calculate the average of all the integers you read, you will need to keep track of the sum of the numbers and the count of how many numbers were entered. Here's how you can modify your code to include this calculation:

#include <stdio.h>

int main()
{
int num;
int min;
int max;
int sum = 0; // variable to store the sum of the numbers
int count = 0; // variable to store the count of numbers entered

printf("Enter a number (-999 to quit): ");
scanf("%d", &num);

// putting the first number the user entered in variable min and max
min = num;
max = num;
sum += num; // add the first number to the sum
count++; // increment the count by 1

while (num != -999)
{
if (num < min)
{
min = num;
}

if (num > max)
{
max = num;
}

printf("Enter another number (-999 to quit): ");
scanf("%d", &num);

if (num != -999) {
sum += num; // add the number to the sum
count++; // increment the count by 1
}
}

printf("\nThe smallest number entered is %d\n", min);
printf("\nThe largest number entered is %d\n", max);
printf("\nThe average of all the numbers entered is %.2f\n", (float)sum / count);

return 0;
}

Explanation:
- I added two new variables, `sum` to store the sum of all the numbers, and `count` to store the count of numbers entered excluding the sentinel value.
- After reading the first number, I added it to the `sum` variable and incremented the `count` by 1.
- Inside the while loop, before asking for the next number, I checked if it is not the sentinel value. If it's not, I added it to the `sum` variable and incremented the `count` by 1.
- At the end, I calculated the average by dividing the sum by the count. I used a typecast to convert one of the variables to float to get a correct floating-point result.
- Finally, I printed the average using %.2f to display it with 2 decimal places.