C++ 1. Asks the user to enter a positive integer greater than or equal to 0 2. V
ID: 3661762 • Letter: C
Question
C++
1. Asks the user to enter a positive integer greater than or equal to 0
2. Validates that the entry is a positive integer
3. Displays the even digits that make up the number entered by the user (assume zero be even)
4. The digits must all be in a single line and separated by a space
5. If no even digits make up the number, then a message indicating that there are no even digit must be displayed
6. The user must be asked if he/she wants to continue entering numbers for numbers or quit.
7. Comment your code
8. Use meaningful or mnemonic variable names
9. RESTRICTIONS: no global variables, no GOTO statements
Explanation / Answer
#include<stdio.h>
#include <iostream>
using namespace std;
int main(){
string choice="y";
while(choice=="y")
{
int number,n,b;
int i=0;
int[] d=new int[100];
cout << "Enter any positive integer greater than or equal to 0 ";
cin >> number;
if(number>=0)
{
i=0;
while(number!=0) {
b=number%10;
number=number/10;
if(b%2!=0) {
d[i]=b;
i++;
}
}
}
n=i;
if(d.Length==0)
{
cout<<"There is no Even Digits"<<endl;
}
else
{
cout<<" Even digits in the integer are"<<endl;
foreach(int i=0;i<=n;i++)
{
cout<<d[i]<<" ";
cout<<endl;
}
}
cout<<" you want to continue entering digits for a number (Y/N)"<<endl;
cin>>choice;
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.