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

Write a C++ program consisting of main plus two other functions which will do th

ID: 3767624 • Letter: W

Question

Write a C++ program consisting of main plus two other functions which will do the following:

Take an integer input from the keyboard.

Send the integer to a function which will output the integer to the screen.

Send the integer to a second function which will tell the user that the integer is an odd value.

Do not tell the user anything if the integer is an even value.

Repeat this process until the user enters something which is not an integer; use input validation to check for validity.

Any not valid input should terminate the program.

Explanation / Answer

#include <iostream>
using namespace std;

void print(int n){
   cout << "Entered number is: " << n << " ";
}

void isOdd(int n){
   if(n % 2 == 1) cout << "The number is odd ";
}

int main(){
   int num;
   while(true){
       cout << "Enter an integer: ";
       cin >> num;
       if(!cin) {
           cout << "Not an integer. Exiting ";
           cin.clear();
           return 0;
       }
       print(num);
       isOdd(num);
   }
}

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