Advertisement
Networking101

oddoreven

Dec 13th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 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 num2;
  12.  
  13. int main() {
  14.  
  15.     while (main)
  16.     {
  17.         int num;
  18.  
  19.         bool isiteven;
  20.         cout << "Enter any number: \n\n";
  21.         //Ask user for the number to the variable "number"
  22.         cin >> num;
  23.  
  24.         //Calling the function that checks if the number is even or odd
  25.         isiteven = isitevenorodd(num);
  26.  
  27.         if (num < 0)
  28.             return 0;
  29.         else if (num > 0)
  30.  
  31.         if (isiteven)
  32.         cout << num << " is even!!!\n\n";
  33.         else
  34.         cout << num << " is odd!!!\n\n";
  35.     }
  36. }
  37. // is the number even or odd. If the number is even then this function returns true else it returns false
  38. bool isitevenorodd(int num) {
  39.     bool b;
  40.     //If number is perfectly divisible by 2 then it is an even number, else it is an odd number
  41.  
  42.     if (num % 2 == 0)
  43.         b = true;
  44.     else
  45.         b = false;
  46.  
  47.     return b;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement