*Please utilize C++ format when answering questions 47. a) Write a function that
ID: 3626488 • Letter: #
Question
*Please utilize C++ format when answering questions47. a) Write a function that reads in from the user (using cin) as many non-negative integer values (ints) from the user as the user wants to enter and then returns, using parameter variables, the sum of all the even integers the user entered and the sum of all the odd integers the user entered. For example, if the user enters the following non-negative values, 1, 3, 8, 9,12, 4, 5, 1, then the sum of even integers would be 24 and the sum of all odd integers would be 19.
b) Write a function call for the function you just defined. Declare, and initialize if needed, any variables you need to make this function call.
Explanation / Answer
please rate - thanks
#include <iostream>
using namespace std;
void sum(int&,int&);
int main()
{int even=0,odd=0;
sum(even,odd);
cout<<"The sum of the even numbers is: "<<even<<endl;
cout<<"The sum of the odd numbers is: "<<odd<<endl;
system("pause");
return 0;
}
void sum(int &e,int &o)
{int n;
cout<<"Enter a number(<=0 to exit): ";
cin>>n;
while(n>0)
{if(n%2==0)
e+=n;
else
o+=n;
cout<<"Enter a number(<=0 to exit): ";
cin>>n;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.