Nested Loop problem:-
Write a C++ program to find first positive even number input. Also tell in how many attempts user input positive even number using do while loop.
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int num;
int i = 0;
do
{
i++;
cout << "Please, enter a value to find the first positive even number: ";
cin >> num;
cout << endl;
} while (num < 0 || num % 2 != 0);
cout << "The first positive even number is " << num << endl;
cout << "Number of attempts are " << i;
}
Comments
Leave a comment