Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int sumArray (int oddEven[], int arraySize);
- int main ()
- {
- int array_size = 0;
- int evenOdd [array_size];
- cout << "Enter the size of the array you wish to create: ";
- while (!(cin >> array_size))
- {
- cin.clear();
- cin.ignore(1000, '\n');
- cout << "\nPlease enter a valid integer: ";
- }
- for(int count = 0; count < array_size; count++)
- {
- cout << "\nPlease enter the value of the element at position " << count << ": ";
- while (!(cin >> evenOdd[count]))
- {
- cin.clear();
- cin.ignore(1000, '\n');
- cout << "\nPlease enter a valid integer: ";
- }
- }
- cout << "\n\nThe result of the sum of the even values minus the sum of the odd values is ";
- cout << sumArray(evenOdd, array_size) << ".\n\n";
- return 0;
- }
- int sumArray (int oddEven[], int arraySize)
- {
- int result;
- int sumEven = 0;
- int sumOdd = 0;
- int count;
- for(count = 0; count < arraySize; count++)
- {
- if((oddEven[count] % 2) == 0)
- sumEven += oddEven[count];
- else
- sumOdd += oddEven[count];
- }
- result = sumEven - sumOdd;
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement