Advertisement
Networking101

OddorEvenUpdated

Dec 11th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <filesystem>
  4.  
  5. using std::cout;
  6. using std::endl;
  7. using std::cin;
  8.  
  9. bool isitevenorodd(int num);
  10.  
  11.     int main() {
  12.  
  13.         while (main)
  14.         {
  15.             int num;
  16.             bool isiteven;
  17.             cout << "Enter any number: \n\n";
  18.             //Ask user for the number to the variable "number"
  19.             cin >> num;
  20.             //Calling the function that checks if the number is even or odd
  21.             isiteven = isitevenorodd(num);
  22.             if (isiteven)
  23.                 cout << num << " is even!!!\n\n";
  24.             else
  25.                 cout << num << " is odd!!!\n\n";
  26.         }
  27.     }
  28.     // is the number even or odd. If the number is even then this function returns true else it returns false
  29.     bool isitevenorodd(int num) {
  30.         bool b;
  31.     //If number is perfectly divisible by 2 then it is an even number, else it is an odd number
  32.    
  33.         if (num % 2 == 0)
  34.             b = true;
  35.         else
  36.             b = false;
  37.  
  38.         return b;
  39.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement