Saturday
May 25, 2013

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 - Write a pseudocode program that asks the user for an integer ...
object oriented programming 1 - write a c++ program that calculates the area of ...
programming - creat a logic for a program that continuously prompts the user for...
java - Write a java application that finds the smallest of several integers. ...
C Programming - Write a program that prompts the user to enter a temperature, ...
computer science - Write an Assembly program to determine the price of a car ...
Programming in c++ - Write a program in c++ that inputs a number [1-12] from the...
Computer programming - Sorting is a common operation used in programming. ...
programming MIPS ask - Write a MIPS assembly language program that will cover ...
Computing - Write a program that displays the following menu: 1 = Square 2 = ...

For Further Reading

Search
Members
Community