Problem #03
Solution Source Code:
Code Overview
1. Header Files and Namespace:
<iostream>
is included for input and output operations.<string>
is included (though not used in this program).using namespace std;
allows the use of standard functions without prefixing them withstd::
.
2. Enumeration Definition (enNumberType
)
- Defines
Odd = 1
andEven = 2
to represent number types.
3. User Input Function (ReadNumber
)
- Prompts the user to enter a number.
- Reads the integer from input and returns it.
4. Number Type Checking Function (CheckNumberType
)
- Determines whether the number is even or odd using
Num % 2
. - Returns
enNumberType::Even
if divisible by 2, otherwise returnsenNumberType::Odd
.
5. Output Function (PrintNumberType
)
- Receives the number type and prints "Number is Even" or "Number is Odd".
6. Program Execution (main()
)
- Calls
ReadNumber()
to get user input. - Calls
CheckNumberType()
to determine if the number is odd or even. - Calls
PrintNumberType()
to display the result. - Returns
0
to indicate successful execution.
This structured explanation ensures clarity and ease of understanding.
0 comments