I'm taking a beginning C++ class right now, and we're supposed to make a program that allows the user to enter as many numbers as they like and when they're done, display the largest and smallest of the numbers entered.
However, I can't figure out how to make it display the largest and smallest number and I've tried everything I can think of. Also, the first number, no matter what is entered, displays the invalid number line.
Any help is greatly appreciated!
//large and small
#include <iostream>
using namespace std;
int main()
{
int number,
small,
large;
small = 100;
large = 1;
cout << "Please enter a number between 1 and 100." << endl;
cin >> number;
while (number < 1 || number > 100);
{
cout << "Invalid number." << endl;
cout << "Please enter a number between 1 and 100." << endl;
cin >> number;
}
while (number >= 1 || number <= 100)
{
if (number < small)
{
small = number;
}
else
if (number > large)
{
large = number;
}
cout << "Please enter another number between 1 and 100." << endl;
cin >> number;
}
cout << "The smallest number is " << small << " and the largest number is " << large << "." << endl;
return 0;
}