Ask the user to enter a number Then tell the user whether th
Ask the user to enter a number. Then tell the user whether the number is positive or negative and whether the number is even or odd. (Note that 0 is considered to be even and positive.) Your program should also make sure that valid input has been entered. After your program has processed a single number, it should ask the user if he wants to try another number. If the user answers yes (y), your program should repeat. If the user answers no (n) your program should end.
Design in C++ and use basic logic
Solution
#include<iostream>
#include<stdlib.h>
using namespace std;
int main()
{
int number;
char choice;
do
{
cout << \"Please input a number : \";
cin >> number;
if(number>=0)
cout << \"Number is positive.\" << endl;
else
cout << \"Number is negative.\" << endl;
if(number%2==0)
cout << \"Number is even.\" << endl;
else
cout << \"Number is odd.\" << endl;
cout << \"Do you want to continue?(y/n) : \";
cin >> choice;
}while(choice != \'n\');
return 0;
}
OUTPUT:
Please input a number : -12
Number is negative.
Number is even.
Do you want to continue?(y/n) : y
Please input a number : 123
Number is positive.
Number is odd.
Do you want to continue?(y/n) : y
Please input a number : 0
Number is positive.
Number is even.
Do you want to continue?(y/n) : n
