Hi could someone please help me with this problem.
I want to find the greatest and least numbers of all current input numbers. My output is wrong. I can't seem to calculate the max/min of all the current input numbers. My code only find the max/min between two inputs.
Here is my driver's code:
/* File: driver1.c
* * Date: February 28, 2010
* */
/* This program gives an output of the greatest or least number given a set of numbers as input */
#include <stdio.h>
#define DEBUG
#include "maxmin.h"
main()
{ /* Variable declarations */
float x; /* N1 of input */
float y; /* N2 of input */
float input; /* Input of N1 and N2 */
float maximum;
float minimum;
/* Obtain two inputs from user */
printf("Enter a real number: ");
input = scanf("%f", &x);
while (input != EOF)
{
/* Invoke function to obtain max of both numbers */
maximum = max(x, y);
#ifdef DEBUG
printf("The maximum of all values is %4.2f\n", maximum);
#endif
/* Invoke function to obtain min of both numbers */
minimum = min(x, y);
#ifdef DEBUG
printf("The minimum of all values is %4.2f\n", minimum);
#endif
x = y
/* Update loop */
printf("Enter a real number: ");
input = scanf("%f", &y);
}
} /* End main */
And here is my header:
/* File: maxmin.h
* Date: February 24, 2010
*/
/* Header file declaring maxmin utility functions */
float max(float n1, float n2);
/* Given: Two real numbers
* * Return: The maximum of all numbers
* */
float min(float n1, float n2);
/* Given: Two real numbers
* * Return: The minimum of all numbers
* */
And these are my functions:
/* File: maxmin.c
* Date: February 28, 2010
*/
/* This file contains driver1's utility functions to determine the maximum and minimum of two given numbers */
#include "maxmin.h"
float max(float n1, float n2)
/* Given: Two real numbers
* * Return: The maximum of both numbers
* */
{
float value;
if (n1 > n2)
{
value = n1;
return value;
}
else
{
value = n2;
return value;
}
}
float min(float n1, float n2)
/* Given: Two real numbers
* * Return: The minimum of both numbers
* */
{
float value;
if (n1 > n2)
{
value = n2;
return value;
}
else
{
value = n1;
return value;
}
}