Use the Do while Loop Write a C++ program that reads 10 integers and then finds
ID: 3591643 • Letter: U
Question
Use the Do while Loop
Write a C++ program that reads 10 integers and then finds and prints the sum of the even and odd integers
***Don't let the user count 10 numbers. Your program should collect only 10 numbers; stop collecting after 10 numbers automatically.
***You assume that the user types only an integer number.
***Use main() function only; no user-defined functions.
***No object-oriented programming.
***Match the output below (output might be different depending on the while loop you are using).
OUTPUT:
Please enter 10 integers:
1 2 3 4 5 6 7 8 9 10
Even sum: 25
Odd sum: 30
Explanation / Answer
#include<iostream>
using namespace std;
int main(){
cout << "Please enter 10 integers: ";
int sumeven = 0;
int sumodd = 0;
int n;
for (int i = 0; i<10; i++){
cin >> n;
if (n%2 == 0)
sumeven = sumeven + n;
else
sumodd = sumodd + n;
}
cout << "Even sum:" << sumeven << endl;
cout << "Even odd:" << sumodd << endl;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.