School-Coding-Cpp/array/array_tutti_pari.cpp

37 lines
863 B
C++

/*
AUTORE: Vichingo455
Function returning if all values stored in an array of values are peer numbers or not
*/
#include <iostream>
#include <array>
#include <vector>
#include <cstdlib>
using namespace std;
bool isPeerArray(int array[], size_t size) {
int numberOfPeers = 0;
for (int i = 0; i < size; i++) {
if (array[i] % 2 == 0) {
numberOfPeers++;
}
}
return numberOfPeers == size;
}
int main() {
size_t numberOfValues;
cout << "Insert the number of values to store on an array: ";
cin >> numberOfValues;
cout << endl;
int array[numberOfValues];
for (int i = 0; i < numberOfValues; i++) {
cout << "Insert the value: ";
cin >> array[i];
}
if (isPeerArray(array, numberOfValues)) {
cout << "All numbers are peers." << endl;
}
else {
cout << "Not all numbers are peers." << endl;
}
return 0;
}