ngurro / hw3

This program functions as a rational number calculator by enabling the user to decide between two arithmetic operations: (A)ddition or (S)ubtraction, then request the input of two rational numbers which will afterward perform the preferred operation and outputs the result in its reduced form.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rational Numbers Calculator

You will be able to perform (A)dditon or (S)ubtraction of rational numbers with this program. Once you run the program, you will be prompted with the following menu:


Rational Numbers Calculator

(A)ddition

(S)ubtraction

(Q)uit

Enter your option:


You can choose which arithmetic operation you'd like to perform on the rational numbers. You may choose to input the letter as lowercase or UPPERCASE. Both forms are accepted.

If you input A or a, you will be prompted with the following menu:

The same menu will be displayed if you input S or s. Only the words "addition/s" will be replaced with "subtraction/s".


Addition of rational numbers

Please enter a fraction (n/d):

Please enter a fraction (n/d):

The result of n/d and n/d = result

Do you want to do more additions? (Y/N):


The first line informs you of which operation you chose. The second and third lines prompt you for the input of two rational numbers.

For example, you may enter 1/2 and 1/2.

The fourth line will display both fractions and the arithmetic operator you chose, and will output the result in its reduced form.

For example you will see the following: The result of 1/2 + 1/2 = 1

Every fraction or result will be reduced by dividing both the numerator and denominator by the greatest common factor.

The fifth line will ask you if you want to continue doing arithmetic operations on rational numbers. Notice that if you choose A the program will continue to add, and if you choose S, the program will proceed to subtract until you choose otherwise. If you input N or n, you will be taken to the Rational Numbers Calculator menu.

After you're taken back to the home menu, you may press Q or q to exit the program.

About

This program functions as a rational number calculator by enabling the user to decide between two arithmetic operations: (A)ddition or (S)ubtraction, then request the input of two rational numbers which will afterward perform the preferred operation and outputs the result in its reduced form.


Languages

Language:C++ 100.0%