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;

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

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


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


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:
while(number != -1){
//do this thing inside

Duplicate post:

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