Create a program in C++ that will store 10 values in an array. Determine how many are odd and how
many are even numbers from the given values and store them in separate arrays, one array that will hold
all even numbers, and another array that will hold odd numbers. Display the values of the 2 arrays.
Well at least the post is in English. Have you attempted to write any of the functions? All I'm gonna say is you'll need a for loop to:
1) push_back the values into each array, and
2) output the values of each array at their respective indices.
#include <iostream>
#include <string>
using std::cout;
using std::cin;
using std::endl;
void askValues(int[]);
int countEven(int[]);
constint LIMIT = 10;
int main() {
int num[LIMIT]; //this will hold 10 numbers
int evenSize = 0, oddSize = 0; //this will hold the number of even and odd numbers respectively
askValues(num); //this will ask 10 values to be stored in the array
evenSize = countEven(num); //this function will return the number of even values
cout << "There are " << evenSize << " even numbers in the array." << endl;
//oddSize = countOdd(num); //this function will return the number of odd values
//int even[evenSize]; //creates the array that will hold even numbers
//int odd[oddSize]; //creates the array that will hold odd numbers
//copyEven(num, even); //this function will copy all even numbers from 1st array to 2nd array
//copyOdd(num, odd); //this function will copy all odd numbers from 1st array to 2nd array
//dispArrayValues(even, evenSize); //this function will display values of the array
//dispArrayValues(odd, oddSize);
return 0;
}
void askValues(int num[])
{
for (int i = 0; i < LIMIT; i++)
{
cout << "Please enter a number: ";
cin >> num[i];
}
return;
}
int countEven(int num[])
{
int count = 0;
for (int i = 0; i < LIMIT; i++)
{
if (num[i] / 2 == 0)
count++;
}
return count;
}