Need Code Help

Hello Guys, I am trying to write a code that lets me input an infinite amount of numbers and save the top 2 largest numbers and the 2 lowest numbers with a minimum user input of 2 times before they are able to use the sentinel number to break out of the program. I can only use basic loops, so no arrays and strings.

This is what I got so far:

#include <iostream>

using namespace std;

int main()
{
int number;
int maxnum=0;
//int num=0;
//int smallnum=0;
//int smallestnum=0;

while(number !=-1){

cout<<"Please type a number between 0 and 10,000"<<endl;
cin>>number;

if (number<=-2 || number>=10000){

cout<<"Invalid entry."<<endl;}

if(maxnum>=-2&&maxnum<=10000){
maxnum=number;}

cout<<"largest number is:"<<""<<maxnum<<endl;

if(number==-1){

cout<<"you have terminated the program, goodbye."<<endl;}


The problem that I am having right now is that when I type in a number greater than 10,000 my code will say "invalid number" but when I terminate the program and tell it to print out the max number it prints out the highest number typed regardless of the condition that it has to be less than 10,000. So for example, if I type 10, 888 this would be the max number printed. Any thoughts??

You'll need a while loop:
1
2
3
4
while(number != -1){
//do this thing inside

}
Duplicate post:

http://www.cplusplus.com/forum/beginner/222379/

Please don't do that.
Topic archived. No new replies allowed.