Write a function called CountIt that has as an argument an integer value. this function will ask the user to enter 10 integers, and will count the number of values entered by the user that are less than the argument passed. if the numbers are LESS, the function returns a 0.
According to the function specification, there will be 2 steps of user input, both in the main() calling CountIt(int) and in the actual function. Once the user inputs a value into an integer value (say, num), you call CountIt(num). Since CountIt(int) returns an integer value, you should store this in a new int variable (say, total). Then just output the total with an appropriate message.
As for the actual function, you must first declare an integer variable (sum) and initialize it to zero (int sum = 0;). You may have luck with a for() loop, looping from 1 to 10, inclusive. Such a loop header would look like this:
- for (int i = 1; i <= 10; i++) {
Inside your loop, define a new integer variable. Ask the user to input a value into this variable. After this, compare the new number to the argument passed to CountIt(int). If the new number is less, increment sum.
Once the loop has finished, return sum. Pseudocode will look like this:
- int CountIt(int myInt) {
-
int sum = 0;
-
for (loop header here; from 1 to 10) {
-
int newNum;
-
input into newNum;
-
if (newNum is less than myInt) increment sum;
-
}
-
return sum;
-
}
Good luck!