hey guys. so Im having problems with this code. I know I'm close but my program cash's every time after entering a number. I need to find the max num as each number is inputed. I can only use one loop.
hers what I have:
#include %26lt;iostream%26gt;
using namespace std;
int main()
{
const int MAXELS = 1000;
int i, max, nums[MAXELS];
cout %26lt;%26lt; "Enter a series of numbers: ";
cin %26gt;%26gt; nums[i];
max = nums[0];
for (i=1;i%26gt;MAXELS;i++)
if (max %26lt; nums[i])
max = nums[i];
cout %26lt;%26lt; "the max num is" %26lt;%26lt;max %26lt;%26lt;endl;
system("PAUSE");
return 0;
}
any ideas?
C++ Arrary that finds the MAXNUM?
Your index needs to go from 0 to i%26lt;mexels
for(i=0;i%26lt;MAXELS;i++)
--------------------------------------...
also
cout %26lt;%26lt; "Enter a series of numbers -1 to stop: ";
cin %26gt;%26gt; nums[i];
Try:
for(int i=0; i%26lt;mexels;i++)
{
cout %26lt;%26lt; "Enter a series of numbers: ";
cin %26gt;%26gt; nums[i];
if(i == -1)
i=mexels;
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment