In a C++ function
How to check if the minimum and maximum values of an array are not equal and the minimum and maximum values of the array are not adjacent to one another.
Also the minimum value occurs exactly once in the array and the maximum value occurs exactly once in the array.

DILJITH.C commented: can u help me in cpp learning?i am just a beginner +0

So...What have you tried so far?

So...What have you tried so far?

max and min is easy
but how to check if they are adjacent
on the other hand what is wrong in this code
I want to see if this array is in ascending order

#include <iostream>
using namespace std;
int main()
{
int a [] = {1,1,3,4,5};
     for( int i=0; i<4; i++)
     if ( a[i]   <  a[i+1] )
     cout<<"true";
     else
     cout<<"False";
return 0;
}

As the code stands, I see nothing wrong with it. It does exactly what you told it to -- tells you if each of two values are in the proper order, and which values.

If that's not what you want, you need to tell us more than "what's wrong with this code". You need to tell us what you wanted, what the code is doing, and what the code should have done. Details. Examples.

As per your first post, now find the min and the max value of the array and display the values to the screen so you can prove you have the correct value.

As the code stands, I see nothing wrong with it. It does exactly what you told it to -- tells you if each of two values are in the proper order, and which values.

If that's not what you want, you need to tell us more than "what's wrong with this code". You need to tell us what you wanted, what the code is doing, and what the code should have done. Details. Examples.

Thanks
I want this funcion to print "true" (just once, not for every element )if the array is in a ascending order

Thanks
I want this funcion to print "true" (just once, not for every element )if the array is in a ascending order

How does that post come close to explaining:

You need to tell us what you wanted, what the code is doing, and what the code should have done. Details. Examples.

I see one question answered. Two unanswered. No details. No examples.
You've fail to supply requested info, and you expect worthwhile help?

How does that post come close to explaining:

I see one question answered. Two unanswered. No details. No examples.
You've fail to supply requested info, and you expect worthwhile help?

//when I run this it returns

truetruetruetrue
which I dont want
I want it to return true just once if all the array elements are in ascending order

Rather than outputting true/false in the loop, set a flag to true before the loop. If any values are not in order, set the flag to false. When the loop is over, output the result.

Rather than outputting true/false in the loop, set a flag to true before the loop. If any values are not in order, set the flag to false. When the loop is over, output the result.

thanks a lot
but could u pls modify the code since am still begginer

No. That's your job. When I was a beginner I had to modify my own code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.