Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Ask the user to enter a number. Then tell the user whether the number is positiv

ID: 3936690 • Letter: A

Question

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

Explanation / Answer

#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

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote