[Dev-C++] My first request for help, problems with Min/Max
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: TornadoChaser <kb...@gm...> - 2005-06-23 18:45:44
|
Hello everyone,
I'm trying to teach myself more C++ than I learned in college through
creating some fun programs. Today I got the idea to write a program
that would take a file in a common format (.txt or .html), find all the
doubles or ints, save them to an array or vector, then sort through them
to find the highest and lowest values. I'm not expecting to get there
in one day, but I'm hoping that I'm on the right track.
My first step was to see if I could determine the min and max of a list
of values, to do this I constructed an array with 5 values, then listed
5 values for each of the subscripts of the array. Next we search the
array for the biggest value, then display the results. I believe that I
wrote the code correctly, but I got some funny results. I'm hoping that
some of the wiser members of the list could help my figure out what my
problem is and perhaps set me on the road to fix it. The code follows
below.
Thanks,
Kevin.
First, the output:
Maximum: 4268036
Minimum: 1
Press any key to continue . . .
Now, the code:
#include <iostream.h>
#include <stdlib.h>
using namespace std;
int main()
{
int numberGroup[5];
int max, min, j = 0;
numberGroup[0] = 1;
numberGroup[1] = 2;
numberGroup[2] = 3;
numberGroup[3] = 4;
numberGroup[4] = 5;
while (j <= 4)
{
if (max <= numberGroup[j]){
max = numberGroup[j];
}
else if (min >= numberGroup[j]){
min = numberGroup[j];
}
j++;
}
cout << "Maximum: " << max << endl;
cout << "Minimum: " << min << endl;
system("PAUSE");
return 0;
}
|