Answer to Question #345730 in C++ for Rida

Question #345730

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.


1
Expert's answer
2022-05-30T08:15:36-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS