#include <stdio.h>
int max(int x, int y);
int min(int x, int y);

int main()	
{
    int grade, total, counter, avg;
    total = 0;
    counter = 0;
    printf("Enter grades: (-1 to end list)\n");
     do
	{
	    scanf("%d", &grade);
	     
		if(grade != -1)
			{
				total = total + grade;
				counter = counter + 1;
				avg = (float)total / counter;
			}
	}
	
	while (grade != -1);
	{
    	 printf("max = %d\n", max);
    	 printf("min = %d\n", min);
    	 printf("average = %0.2f\n", (float)total/counter);
	}
}

int max(int x, int y)
{
    int biggest = x;
    if (y > biggest)
        biggest = y;
    return biggest;
}

int min(int x, int y)
{
    int smallest = x;
    if (y < smallest)
    	smallest = y;
    return smallest;
}

i need help finding the maximum and minimum values inputed by the user. i keep getting values such as 67808 and 67880 as my maximum and minimum values when those are not values inserted by the user. somebody help please!

Recommended Answers

All 4 Replies

Do you need to do this without calling library functions?

I'm assuming you need to find the maximum and minimum grade of the whole set. Since your max and min functions only compare two grades (and you never call them -- you'll get an error if you try to compile what you have above), they need to be called for every grade entered. This should get you started.

Please use code tags in future.

This is definitely one issue:

printf("max = %d\n", max);
printf("min = %d\n", min);

max and min are not integers, they are functions that return integers, so these lines of code don't make any sense. I'm not even sure how you got this to compile, but your program is probably printing out the memory addresses of your min() and max() functions.

You're not even recording any of your grade's values anyway, so it will be impossible to know what the maximum and minimum grades are the way you wrote your code.
HINT: You need to recalculate the minimum and maximum values inside your loop.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.