For each of the problems below you are to consider making a function to solve th
ID: 3862101 • Letter: F
Question
For each of the problems below you are to consider making a function to solve the problem. As before, state the purpose of the function in your own words. Next specify input that is needed for the function to complete the task, and state what input should be passed to the function as parameters and what would be acquired inside the function using the input function. Specify the expected output and state if the output will be returned to the function call or be sent to the monitor. Finally give the step by step process that will obtain the output from the input (the algorithm). In addition to these 4 items also specify test data that can be used for each function. Remember to describe your steps in enough detail so someone other than you could follow your algorithm and solve the problem. Also do not write any actual code.
Program 1: Describe a function that will prompt the user to enter 50 whole numbers and count how many even and odd numbers were entered (0 should be considered an even number). The function should send back to the function call how many odd and even numbers were entered.
Explanation / Answer
#include<iostream>
using namespace std;
void check_even_odd()
{
int even=0,odd=0,i=0,n;
cout<<"Enter 50 whole numbers:";
while(i<50)
{
cin>>n;//taking input..
//finding whether even or odd
if(n%2 == 0)even++;
else odd++;
i++;
}
cout<<"Number of Even numbers:"<<even<<endl;//printing number of even numbers
cout<<"Number of Odd numbers:"<<odd<<endl;//printing number of odd numbers....
}
int main()
{
check_even_odd();
return 0;
}
output:-
Enter 50 whole numbers:1 2 3 4 45 6 7 89 2 3 4 5 0 3 4 5 6 3 3 4 5 67 8 8 93 43 4 3
1 2 3 4 5 6 7 8 9 0 02 3 4 4 5 6 7
1 2 23 4 5 6 7 8 999 43 3 4 23 4 5 6
Number of Even numbers:23
Number of Odd numbers:27
Process exited normally.
Press any key to continue . . .
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.