Vectors

Hello, I'm trying to write a code, for homework assignment, called increasing. What the program is supposed to do is, finding out if numbers that the users inputs are increasing or not. E.g, 1 2 3 4 are increasing, while 1 3 2 4 is not.

I'm currently getting this error, that says; Too few arguments to function 'bool increasing (std::vector<int>, int*, int'

in line 18, and it should be declared in line 6.

However, since it is declared, I don't really see the problem, and am thinking it may be lying elsewhere.

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
27
28
29
30
31
32
33
34
35
#include <iostream>
#include <vector>
using namespace std;


bool increasing(vector<int> arr, int numbers[], int size);
int main()
{
    int n;
    while (cin >> n)
    {
        vector<int> arr(n);
        for (int i = 0; i < n; i++)
        {
            cin >> arr[i];
        }

        cout << (increasing(arr) ? "increasing" : "not increasing") << endl;
    }

    return 0;
}
bool increasing(vector<int> arr, int numbers[], int size)
{
	int last = numbers[0];
	for(unsigned int i = 0; i < (arr.size()); ++i)
    {
		if(numbers[i] < last)
		{
			return false;
		}
		last = numbers[i];
	}
	return true;
}
Last edited on
All you have to do is make a copy of the vector, sort it, and use the == operator to see if they are the same.
1
2
3
auto sorted = original;
std::sort(std::begin(sorted), std::end(sorted));
std::cout << std::boolalpha << (sorted == original) << std::endl;
Last edited on
@LB: increasing. Consider repeated elements.

@OP: This is your prototype bool increasing(vector<int> arr, int numbers[], int size);
Count the arguments

This is your call increasing(arr)
count the arguments

¿don't you see anything weird?
@ne555: I'm not sure what you think is wrong? They're just integers, unless two integers representing the same value can compare inequal...
0 0 0 0 0 0 0
is not an increasing sequence, but it is sorted.
Oh, I see what you mean - I would personally consider that both ways, but it does depend on the assignment's requirements.
Topic archived. No new replies allowed.