finding maximum

this is to find the maximum of ten input values
but the programme gives the answer what I have entered last
how can I correct it?

#include<iostream>
using namespace std;
void inputheight(float height[],int size);
void findmax(float height[],int size);
int main()
{
float pheight[10];
inputheight(pheight,10);
findmax(pheight,10);
return 0;
}
void inputheight(float height[],int size)
{
for(int i=0;i<size;i++)
{
cout<<"Input Height: ";
cin>>height[i];
}
}
void findmax(float height[],int size)
{
float max;
for(int i=1;i<size;i++)
{
max=height[0];
if(max<height[i])
{
max=height[i];
}
}
cout<<"max is: "<<max;
}
Line 25 doesn't belong inside the loop, but before it. Please use [code] tags.
Last edited on
The best way to fix it is to delete your implementation and use one that already works and is built into the C++ language.
http://cplusplus.com/reference/algorithm/max/
http://cplusplus.com/reference/algorithm/min/
Topic archived. No new replies allowed.