Well they want me to keep asking for numbers, once the user puts in a negative number the program is supposed to stop and inform the highest and the lowest number that the user provided. But the thing is, I am not sure if the negative number counts and so far I got it working if that's the case.
Can someone help me with getting the lowest not to get the negative number?
This was such a hack-y and pointless solution that I almost cried...
You just placed an if around a do...
Correct me if I'm wrong, the point of using the do is so that the check is performed after the code is run. Don't put an if around it. Use a while loop.
Real Solution :
#include <iostream>
usingnamespace std;
int main()
{
int A, LOW=std::numeric_limits<int>::max(), HIGH=0;
// why were you using a float there? seems kinda weird...
// I changed your low to be the highest integer the computer can handle. :3
cout << "Please pick any number: " <<endl;
cin >> A;
while (A>=0)
{
cout << "Please pick any number: " <<endl;
cin >> A;
if ((A>=HIGH) && (A>=0))
{
HIGH = A;
cout << endl << "NEW HIGH" << endl << endl;
}
if ((A<=LOW) && (A>=0))
{
LOW = A;
cout << endl << "NEW LOW" << endl << endl;
}
}
cout << "The highest number you picked was: " << HIGH << endl;
cout << "The lowest number you picked was: " << LOW << endl;
getch(); // Don't use system... :S
return 0;
}
lol that made me laught a good bit.
well everything worked out besides the getch(); part. why should I use system?
and I also fixed some stuff up on the code since it was saying stuff i didnt want it to.
i just left the system in becuase i dont know what it does, and the float thing was becuase i didnt know what to put, thanks for the tips, i was wondering if i could put it to the limit.
Most people here hate system() because while it provides lots of extra functionality without writing extra code, it has horrible overhead, is a potential security hole, and above all is platform dependent.
Seriously, don't use system() if you want to avoid getting bashed on this forum.
The problem here is that the first number entered is not counting towards the LOW, but it is counting towards HIGH. Since all the subsequent non-negative numbers are above the initial number, nothing is being assigned to LOW. Consequently LOW is just outputting whatever value is in the memory.
Sorry, that was my bad.
I forgot that it was a part of conio.
Add the following after your first include: #include <conio.h>
Then getch(); will work.
Basically, what getch does is it takes the input of one character.
So the program will hang until a key is pressed.