166k views
0 votes
How would i do this?

Create a program that will do the following
• Ask the user to enter an unknown set of integers, and stop when they enter 9999
• Add up all the even numbers.
• After the loop, print the sum of the even numbers with a label

1 Answer

4 votes

Answer:

#include <iostream>

using namespace std;

int main() {

int num = 0, sum = 0;

do {

cin >> num;

if (num % 2 == 0) {

sum += num;

}

} while (num != 9999);

cout << "The sum of the even numbers is " << sum;

}

User Davidvera
by
4.9k points