write a program executing a loop,which is readinginteger numbers from the keyboard until at least one of the below listed conditions is fulfilled
1.the multiplication of these numbers exceeds 1000
2.the number of reported even numbers exceeds 10
3.three subsequent numbers will have exactly the same value (eg 3,4,2,5,5,5)
#include <iostream>
using namespace std;
int main() {
int x;
int product=1;
int num_even=0;
int prev;
int num_prev=0;
while (true) {
cout << "Enter an integer: ";
cin >> x;
product *= x;
if (product > 1000) {
cout << "Product: " << product << " is greater than 1000" << endl;
break;
}
if (x % 2 == 0) {
num_even++;
}
if (num_even > 10) {
cout << "More than 10 even number" << endl;
break;
}
if (num_prev == 0) {
num_prev = 1;
prev = x;
}
else {
if ( prev == x) {
num_prev++;
}
else {
num_prev = 1;
prev = x;
}
}
if (num_prev == 3) {
cout << "Meet " << prev << " three subsequent times" << endl;
break;
}
}
return 0;
}
Comments
Leave a comment