Write a C program that prompts the user to enter an integer
Write a C++ program that prompts the user to enter an integer number. After the number is entered your program will compute whether the number entered in even or odd. Your program will then prompt the user if they want to continue. If the character n or N is entered the program will stop; otherwise, the program will continue. Be sure to use a C++ function to test if the number is even or odd. The function should return true if the number is even, and false otherwise.
Solution
So to follow the Given Guidelines we need have a following program
#include <iostream>
using namespace std;
main()
{
int a;
char b,N,Y;
cout << \"Enter a Number:\" << endl;
cin>> a;
if (a%2==0) /*Check if Number is Even or Odd*/
{
cout<<\"True\"<<endl;
}
else
{
cout<<\"False\"<<endl;
}
cout<<\"To Continue Press Y, to Exit Press N\"<<endl; /*Prompt to Enter Y or N*/
cin>>b;
while(true) /*Intialise continue and Break in a Loop other wise it will give an error*/
{
if(b=\'Y\')
{
continue;
}
else
{
break;
}
}
return 0;
}
Comments are added after each line for your better understanding...
Thank You for using Chegg...
