Link to home
Start Free TrialLog in
Avatar of pgmerLA
pgmerLA

asked on

find max using class

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

ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial