Saturday
August 23, 2014

Homework Help: C programming

Posted by E on Saturday, October 2, 2010 at 7:49pm.

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;
}

Answer this Question

First Name:
School Subject:
Answer:

Related Questions

Programming in c++ - Draw a flow-chart and Write a program that asks the user ...
programming MIPS ask - Write a MIPS assembly language program that will cover ...
C programming - Build a program that allows a user to select one of the ...
C Programming - Write a program that prompts the user to enter a temperature, ...
Programming - Write a pseudocode program that asks the user for an integer ...
Computer Science - write a program that will prompt the user for a value and ...
programming - Write a program which allows user to enter 10 student names and ...
programming - Create the logic for a program that continuously prompts a user ...
programming pseudocode - Create the logic for a program that continuously ...
programming - Pseudocode - Create the logic for a program that continuously ...

Search
Members