We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

find max using class

pgmerLA
pgmerLA asked
on
Medium Priority
356 Views
Last Modified: 2012-05-11
Hi, I am trying to find the max using class

my input is:5 88 24 0 4
but my max is 0 instead of 88.

Can you tell me what is wrong with my code?

THANKS.
#include<iostream>

using namespace std;
class Three
{private: int a[5];
public: void Read();
		void FindMax();
};
void Three::Read()
{for(int i=0;i<5;++i)
cin>>a[i];
}

void Three::FindMax()
{int max=a[0];
for(int i=1;i<5;++i)
{if(max>a[i]) max=a[i];}
cout<< max;
}
int main(){
	Three One;
One.Read();
One.FindMax();

return 0;
}

//input: 5 88 24 0 4
//max: 0

Open in new window

Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2012
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Top Expert 2016
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.