I'm trying to make a program that allows the user to input an arbitrary amount of numbers and finding the largest of all the inputs but I keep having problems with the output.
Also I can't figure out the format to insert my code so that it shows lines and such; I'm new to this site. Apologies if its a pain to read.
javascript:tx('
#include <iostream>
using namespace std;
comparator::comparator()
{
cout << "Enter numbers you want to compare: ";
return;
}
void comparator::getMaxNum()
{
cout << "\n\nDid we get to this part?" << endl << endl;
int num;
while ( (num = cin.get() ) != EOF) // THIS LINE HERE I THINK IS MY TROUBLE
{
cin >> num;
if (num > maxNum)
{
maxNum = num;
} // end if
} // end while
return;
} // end function getMaxNum
void comparator::displayMaxNum() const
{
cout << "The highest number you entered was " << maxNum << endl;
return;
}
//**********************************************************
// MAIN
//**********************************************************
int main()
{
comparator compareNums; //Initializes object to compare numbers, calling constructor to print message
compareNums.getMaxNum();
cout << endl << endl;
compareNums.displayMaxNum();
return 0;
}')
and regardless of what numbers I enter, I always get the output of 10 and I have no idea why.
Also I got the EOF idea from my textbook so if there is a better way of doing this I'd like to hear it. I don't know any clear ways that looks nice to end the while loop when the user doesn't have any more numbers to enter. Thanks.