Hi can anyone help me, I am learning the language C but need some help writting some code. what i need to do is from the input of the keyboard i need to find the max and min of some values and out put them. what i got so far is:

// Program to select a Maximum and Minimum from inputted numbers.

#include <stdio.h>
#include <conio.h>

int main ()
{


   
   int numtimes;
   int tempnum1, tempnum2, tempnum3;
   char indicator = 'y';
   


   clrscr();

   do
   {
      printf("\nEnter a number ");
      scanf(" %d", &tempnum1);

      printf("\nEnter a second number ");
      scanf(" %d", &tempnum2);

      printf("\nEnter your thrid number ");
      scanf(" %d", &tempnum3);

      printf("\nWould you like to continue? (enter n to exit) ");
      scanf(" %c",&indicator);


   }while((indicator == 'y') || (indicator == 'Y'));

  // WHAT DO I DO NOW? ANY IDEAS?


   getch();



  return 0;

}

Hi can anyone help me, I am learning the language C but need some help writting some code. what i need to do is from the input of the keyboard i need to find the max and min of some values and out put them. what i got so far is:

// Program to select a Maximum and Minimum from inputted numbers.

#include <stdio.h>
#include <conio.h>

int main ()
{
int numtimes;
int tempnum1, tempnum2, tempnum3;
char indicator = 'y';

clrscr();

do
{
printf("\nEnter a number ");
scanf(" %d", &tempnum1);
//assign max and min to tempnum1, here

printf("\nEnter a second number ");
scanf(" %d", &tempnum2);
//add the two testing if statements, here

printf("\nEnter your thrid number ");
scanf(" %d", &tempnum3);
//add the two testing if statements, here as well

printf("\nWould you like to continue? (enter n to exit) ");
scanf(" %c",&indicator);


}while((indicator == 'y') || (indicator == 'Y'));

// WHAT DO I DO NOW? ANY IDEAS?

getch();

return 0;

}

Please select your code and click on "#" to wrap it in code tags for the forum - always!

Your first number is both the minimum and the maximum, so far, so assign those variables to it:

max = tempnum1;
min = tempnum1;

Now use an if statement to test if any later numbers that are entered, are higher or lower:

if(tempnum2 > max)
   max = tempnum2;

if(tempnum2 < min)
   min = tempnum2;

and repeat both the above if statements for each tempnumber that is entered.

If the user loops back around in the do loop, you'll be OK, still, with this logic.

Thank you very much mate.

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.