im a beginer in C and im writing a program that ables the user to repeatedly enter positive and integers, until the user enters a value <=0. Then prints the min and max value entered.


I wrote the program but for some reason the min and max functions that i wrote don't work if some one can tell me where im going wrong with this it would be greatly appreciated.

thank you

#include <stdio.h>
#include <stdlib.h>


int main ()

{
    
    int i,max,min;
    
    
    printf("enter an intiger: ");
    scanf("%d",&i);
 


if (i>max)
max=i;

if (i<min)
min=i;

while (i>0 || i!=i)
    {
          printf("\nenter an integer: ");
          scanf("%d",&i);
     }



printf("\n\n the min # is: %d", min );
printf("\n\n the max # is: %d", max );

system ("pause");
return 0;

}

im a beginer in C and im writing a program that ables the user to repeatedly enter positive and integers, until the user enters a value <=0. Then prints the min and max value entered.

I wrote the program but for some reason the min and max functions that i wrote don't work if some one can tell me where im going wrong with this it would be greatly appreciated.

thank you

#include <stdio.h>
#include <stdlib.h>


int main ()

{

    int i,max,min;


    printf("enter an intiger: ");
    scanf("%d",&i);



if (i>max)
max=i;

if (i<min)
min=i;

while (i>0 || i!=i)
    {
          printf("\nenter an integer: ");
          scanf("%d",&i);
     }



printf("\n\n the min # is: %d", min );
printf("\n\n the max # is: %d", max );

system ("pause");
return 0;

} 

end quote.

You never initialize i, min, and max. I think you should consider putting your if statements inside your while loop. Also, this looks like C, not C++ code. There's a C forum on Daniweb.

Edited 3 Years Ago by mike_2000_17: Fixed formatting

This article has been dead for over six months. Start a new discussion instead.