Rational Numbers Calculator is a command-line application designed to perform basic arithmetic operations (addition, subtraction, multiplication, and division) on rational numbers (fractions). It can handle both positive and negative fractions, simplify results automatically, and detect invalid inputs, such as zero in denominators.
- Supports Addition, Subtraction, Multiplication, and Division of fractions
- Handles simplification of results automatically
- Detects invalid inputs (e.g., zero in the denominator)
- Accepts both fractions and whole numbers in calculations
- User-friendly prompts and input validation
- C++ compiler (such as GCC, MinGW, or Visual Studio)
- Basic knowledge of command-line operations
- Clone the Repository
git clone https://github.com/yourusername/rational-numbers-calculator.git
- Navigate to the Project Directory
cd rational-numbers-calculator
- Compile the Program
g++ -o RationalCalculator main.cpp
- Run the Program
./RationalCalculator
- Input Format: Enter two fractions separated by an operation symbol. The supported format is
[numerator/denominator] operation [numerator/denominator]
. - Operation Options:
+
(addition),-
(subtraction),*
(multiplication),/
(division).
After entering your expression, the program will display the simplified result. You can choose to perform additional calculations or exit.
- Form:
num/num operator num/num
- Operators:
+
,-
,*
,/
- Examples:
3/4 + 2/5
7 * 1/3
5/6 - 3/8
- Notes:
- Whole numbers are accepted (e.g.,
5 * 3
). - Avoid entering
0
in the denominator.
- Whole numbers are accepted (e.g.,
- Input:
1/2 + 3/4
- Output:
The Result = 5/4
- Input:
5/6 - 1/3
- Output:
The Result = 1/2
- Input:
2/3 * 3/4
- Output:
The Result = 1/2
- Input:
4/5 / 2/3
- Output:
The Result = 6/5
Below are sample test cases to verify the calculator's functionality.
-
Input:
1/2 + 3/4
Expected Output:5/4
-
Input:
2/3 * 3/4
Expected Output:1/2
-
Input:
1/0 + 1/2
Expected Output:Please don't enter a zero in the denominator.
-
Whole Number Input
Input:5 * 3
Expected Output:15/1
-
Exit Prompt
Follow-Up Prompt:Do you want to continue?\n [1] Yes.\n [2] No.
Input:2
Expected Outcome:Thanks For Using Rational Number Calculator ....
and program exits.
- Fork the repository.
- Create a new branch.
- Make your changes.
- Submit a pull request.
Contributions are welcome for new features, bug fixes, and improving documentation.
- Mohammed Atef Abd EL-Kader (20231143)
- Esraa Emary Abd Elsalam (20230054)
- Aly El-Deen Yasser Aly (20231109)
This project is licensed under the MIT License. See LICENSE
for details.