View Single Post
Old Apr 10th, 2005, 10:36 PM   #5
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
I was bored... here is an example of getting the max number... i believe math.h has a max function you could use as an alternative... i'm sure some more complex data algorithms also have this available... but if all you had to use was the if else, etc... this will work.

#include <iostream>
#define EVER ;;
using namespace std;

int CheckMax (int x);
int GetNums (void);
int MAX = 0;

int main (void)
{
   for (EVER)
   {
      GetNums();
   }
}

int GetNums (void)
{
   int myNum = 0;
   cout << "Enter number (-1 to quit): " << endl;
   cin >> myNum;

   if (myNum != -1)
     CheckMax(myNum);
   else
   {
     cout << "The maximum value entered: " << MAX << endl;
     exit(0);
   }
   return 0;
}

int CheckMax (int x)
{
   if (x > MAX)
       MAX = x;

   return 0;
}

Enter number (-1 to quit):
4
Enter number (-1 to quit):
19
Enter number (-1 to quit):
432
Enter number (-1 to quit):
51
Enter number (-1 to quit):
5326
Enter number (-1 to quit):
13526523
Enter number (-1 to quit):
234234
Enter number (-1 to quit):
-1
The maximum value entered: 13526523
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote