Write a function named totalEvens that computes the total number of even integers that are less than a given threshold. The function takes one parameter: 1. threshold, an integer The function repeatedly asks the user to enter a number until -1 is entered. The function returns the total number of even integers less then threshold. For example, if threshold is 10 and user enters: 5 4 7 20 12 -1 The function would return 1. (USE C++)
#include <iostream>
using namespace std;
int totalEvens(int threshold) {
int count = 0, num;
while (true) {
cout << "Enter a number(-1 to exit): ";
cin >> num;
if (num == -1) break;
if (num < threshold && num % 2 == 0) {
count++;
}
}
return count;
}
int main() {
int t;
cout << "Enter a threshold value: ";
cin >> t;
int n = totalEvens(t);
cout << "Number of evens entered is " << n << endl;
return 0;
}
Write a function named totalEvens that computes the total number of even integers that are less...