Question: Using a C++ language I need a program that takes a numerator and a denominator as a user input and reduces the fraction to its

Using a C++ language I need a program that takes a numerator and a denominator as a user input and reduces the fraction to its lowest terms. You need to do error handling for the input, which means that it should not accept float number or any char inputs, however it can accept negative whole numbers. Denominator cannot be zero and if there is any "bad" input program should reprompt a user. At the very end a program should ask a user if they want to do another conversion. Finally, there are 2 functions that are required to use:

1) bool to_lowest_terms(int &numerator, int &denominator); This function returns false if denominator is 0, true in any other cases and at the same time reduces both numerator and denominator to lowest terms inside the function. // Idk why, but we have to use pass by reference here

2) int GCD(int num1, int num2); - This function finds the greatest common divisor (gcd) for the numerator and denominator. Please note that this must be a recursive function (calling itself)

You also can create as many other functions as you want, however the functions should not be longer than 15 lines. Please make sure to use pass by reference, not pass by value. Many thanks in advance. Here is an example run:

Please enter your numerator: hello123

Invalid input, enter your input once again:

Please enter your numerator: 1.1

Invalid input, enter your input once again:

Please enter your numerator: 10

Please enter your denominator: -20

The lowest terms of your fraction is -1/2

Do you want to run a program again (0-no, 1-yes) ?

0

//program ends

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!