431,785 views
33 votes
33 votes
Write a loop that reads positive integers from console input, printing out those values that are even, separating them with spaces, and that terminates when it reads an integer that is not positive. Declare any variables that are needed.

User Murena
by
2.6k points

1 Answer

17 votes
17 votes

#include <iostream>

#include <vector>

std::vector<int> v;

int main(int argc, char* argv[]) {

while(1) {

int temp;

std::cout << "\\Enter a number: ";std::cin>>temp;

if(temp<0) {

std::cout << "\\Even number(s) is/are:\\---------------------\\";

for(int i=0;i<v.size();i++) {

if(v.at(i)%2==0) std::cout << v[i] << " ";

else continue;

}

std::cout << std::endl;

break;

}else {

v.push_back(temp);

}

}

return 0;

}

Write a loop that reads positive integers from console input, printing out those values-example-1
User Kiedysktos
by
3.2k points