My task is to find the minimum number between n input values that the user should enter in an infinite loop until a certain number or character is entered to stop the loop.
The problem that I am facing is, I can't get the condition that tests the input to see which of the entered numbers is the smallest to work. Also, a second problem is, I want to end the loop with a char not an int, but I don't know if that is even possible.
I searched online but I can't find any answers.
Side note: I am new to C++. I am using Borland C++ v5.02.
#include <iostream>
#include <conio.h>
int I, min =0;
cout<<"Enter a number :";
do{
cin >> I;
if (I < min){
if (I > 0){
min = I;
}
}
}while (I > -1);
cout << min;
the problem with the code was with the header I couldn't find a one that was working with my compiler Borland v5.02 c++ but thanks to @JerryJeremiah he leads me to it.
also, I redeclared the min =INT_MAX;
because I am using this code in a loop.
the code is working with me now.
#include <iostream>
#include <conio.h>
#include <limits.h>
int main()
{
int I, min =INT_MAX;
cout<<"Enter number of input :";
do{
cin>>I;
if (I<min ){
if(I>0){
min =I;
}
}
}while(I>-1);
cout<<min;
min =INT_MAX;
getch();
}