Check that enter number is even , odd or prime ............unless the user press (n)

#include <iostream>
using namespace std;

void main ()
{
char test='y';
int i=1;
int ans=0;
int counter=0;

for (int j=1; j<=2;) // for repeat the Q again and again
if (test=='y' || test=='Y')
{

cout<<"Please enter the number here:";
int number;
cin>>number;

if (number<0) // check a positive number
cout<<"You can only enter a positive number"<<endl;

else 
{
if (number==1)
cout<<"The number is prime."<<endl;
else
{
while (i<=number)
{

if (number%i==0)
 counter++;

  i++;
}
}
if (counter==2)
 cout<<"The number is prime"<<endl;

if (number%2==0) // for even number
cout<<"The number is even..."<<endl;

else 
cout<<"The number is odd..."<<endl;
cout<<"Press Y to continue and N to end: ";
cin>>test;
}
}

else
break;
cout<<"\nThank you for using this...";


}

Comments

Popular posts from this blog

Umbrella activities in Software Engineering

Operating System | Best Definition of Opetating System