You need to either store them all in an array then iterate over the array to find the highest.
but an easier (and very unelegant and lazy ) way would be to do something like this:
How large is the largest number before any numbers have been given?
You could answer: "There is no such value", but that is not practical here. Therefore, lets set the value to something.
What would be a good value? Obviously every number given by the user must be larger or equal to that initial guess. So small, very small.
Ok, now we have a variable that holds the highest value.
Lets read one number from the user. That number is either higher than highest, or not. In the former case the highest has to be updated.
Repeat that previous step as many times as you need.
// DisplayHighestNumber.cpp
#include <iostream>
usingnamespace std;
//Function Declarations
void BubbleSort(int numbers[]);
constint SIZE = 6;
int main()
{
int numbers[SIZE];
int i = 0;
int numOfElements = 0;
int input;
cout << "Enter number: " << endl;
while (i < SIZE - 1)
{
cin >> input;
cout << "Enter number: " << endl;
numOfElements++;
numbers[i] = input;
i++;
}
for (int i = 0; i < numOfElements; i++)
{
cout << numbers[i] << endl;
}
BubbleSort(numbers);
cout << "\nAfter sort:" << endl;
for (int i = 0; i < numOfElements; ++i)
{
cout << numbers[i] << endl;
}
return 0;
}
//Function Definitions
void BubbleSort(int numbers[])
{
// The outer loop, going through all list
for(int i = 0; i < 5; i++)
{
//Inner loop, going through element by element
int nrLeft = 5 - i; // To se how many has been gone through
for (int j = 0; j < nrLeft - 1; j++)
{
if (numbers[j] < numbers[j+1]) // Compare the elements
{
swap(numbers[j], numbers[j+1]);
}
}
}
}