Question: C++ Write a function that takes as arguments two integers representing a range (eg. 3 - 12; 2 - 22) and have it return a
C++
Write a function that takes as arguments two integers representing a range (eg. 3 - 12; 2 - 22) and have it return a count of the range of numbers between the lowest and highest even number in the range (inclusive). As a side-effect, also return the lowest and highest even values in the range. If first is greater than last, reurn -1 to indicate an error. When there's an error, don't change lowest or highest.
Remeber that functions cannot return more than one value in the return statemen.t You have to use another idea here. You should use the return statement to return the range and parameters to return the lowest and highest even value.
#include
// ToDo: declare your function here.
int main() { int first, last, range;
cout << "Enter the first value in the range: "; cin >> first; cout << "Enter the last value in the range: "; cin >> last; /* ToDo: call your function here and set range to the return value. */; cout << "The size of the range is " << range << endl; if (range > 0) { // ToDo: Print the computed values here. cout << "The lowest even value is " ; cout << "The highest even value is " ; } return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
