#include <iostream>
#include <iterator>
#include <vector>
using std::cout; using std::endl; using std::cin;
using std::begin; using std::end;
using std::vector;
int main()
{
int arr[] = {1,2,3,4,5};
int arr2[] = {1,3,3,4,5};
if (end(arr) - begin(arr) == end(arr2) - begin(arr2)) {
cout << "The first array has the same amount of elements as the second one." << endl;
unsigned counter = 0;
while (counter != end(arr) - begin(arr) && arr[counter] == arr2[counter]) {
++counter;
if (counter == end(arr) - begin(arr)) {
cout << "Elements are the same to." << endl;
}
}
}
elseif (end(arr) - begin(arr) > end(arr2) - begin(arr2)) {
cout << "The first array is larger than the second" << endl;
}
elseif (end(arr) - begin(arr) < end(arr2) - begin(arr2)) {
cout << "The second array is larger than the first" << endl;
}
return 0;
}
PROBLEM
This was my first code, I don`t understand the commented line
#include <iostream>
#include <iterator>
#include <vector>
using std::cout; using std::endl; using std::cin;
using std::begin; using std::end;
using std::vector;
int main()
{
int arr[] = {1,2,3,4,5};
int arr2[] = {1,2,3,4,5};
if (end(arr) - begin(arr) == end(arr2) - begin(arr2)) {
cout << "The first array has the same amount of elements as the second one." << endl;
unsigned counter = 0;
while (counter != end(arr) - begin(arr) && arr[counter] == arr2[counter]) {
if (counter == (end(arr) - begin(arr)) - 1) { // so if 4 of the 5 elements are equal?
cout << "Elements are the same to." << endl;
}
++counter;
}
}
elseif (end(arr) - begin(arr) > end(arr2) - begin(arr2)) {
cout << "The first array is larger than the second" << endl;
}
elseif (end(arr) - begin(arr) < end(arr2) - begin(arr2)) {
cout << "The second array is larger than the first" << endl;
}
return 0;
}
Edit again, okay after breaking my head I have got it. Thank you