Help Please!!

Can someone please help me to understand what my prof wants in this program. I am a little confused on what he wants us to put in the for loop. Here is the question:
Write a function according to the following specifications:
• The function will attempt to determine whether a sequence (array) of values are monotonically increasing; i.e., at no time is one value less than the previous one. When two or more values are the same, they are still considered to be monotonically increasing. (Any decreasing between values denotes that the sequence is not monotonically increasing.)
o Return data type: bool
o Function name: is_monotonic
o Two parameters:
- First data type: double (array)
- Parameter name: data
- Second data type: int
- Parameter name: size // i.e., how many elements are in the data array
o In the body of the function’s definition:
- Write a for-loop to iterate from element 0 until the second-to-last element. For example, if size were 10 elements, your loop would iterate from 0 to 8 (the last element, 9, is omitted because the monotonicity will be determined by comparing the current element, I, to the next element, I + 1.
- In the body of the loop, if element I is less than element I + 1, return false.
- If the iteration through the loop finishes without returning false, return true.

This is what I have so far.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
using namespace std;

bool is_monotonic(double data[], int size);

int main()
{


	return 0;
}

bool is_monotonic(double data[], int size)
{
	for ()
	{
		if (i < i + 1)
		{
			return false;
		}
	}
}


Any help would be greatly appreciated!Thank you!!
if (i < i + 1)

wrong comparison, because its always true, i +1 > i

compare, data[one] vs data[two]

use for loop like this:

for(int i=0; i<=size-2; i++)
Last edited on
I am sorry but this does not explain it to me... it just gives me the answer and that is not what I want.
the question asks to check these:

1 3 4 6 6 6 7 19 24 > ok

1 5 4 8 9 > not ok (because 5>4)
Are those just random numbers? Where does that come in? Do I need to ask the user for them?
Ok this is what I have. It is giving errors when I try to build it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
using namespace std;

bool is_monotonic(double data[], int size);

int main()
{
	double data[];
	int size;

	cout << is_monotonic(data[], size) << endl;

	return 0;
}

bool is_monotonic(double data[], int size)
{
	for (int i = 0; i <= size -2; i++)
	{
		if (i < i + 1)
		{
			return false;
		}
		return true;
	}
}


these are the errors given:
Error 1 error C2133: 'data' : unknown size
Error 2 error C2059: syntax error : ']'
Error 3 IntelliSense: incomplete type is not allowed
Error 4 IntelliSense: expected an expression

I am so lost on this question.
This is what I have now. There are no errors but I feel like this is still incorrect.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
using namespace std;

bool is_monotonic(double data[], int size);

int main()
{
	bool is_monotonic(double data[], int size);

	return 0;
}

bool is_monotonic(double data[], int size)
{
	for (int i = 0; i <= size -2; i++)
	{
		if (i < i + 1)
		{
			return false;
		}
		return true;
	}
}
why aren't you using data[]
Topic archived. No new replies allowed.