Question: Problem Statement: You are tasked to write a program which takes a numerator and a denominator as a user input and reduces the fraction to
Problem Statement: You are tasked to write a program which takes a numerator and a denominator as a user input and reduces the fraction to its lowest terms. For example, if a user inputs 48 as numerator, and 9 as denominator, then your program should output 16/3. This will require finding the greatest common divisor (gcd) for the numerator and denominator, then dividing both by that number. If the denominator is 0, an error message should be printed. At the end of each calculation, the user should be asked if they want to do another conversion or exit the program. The program must handle all types of bad inputs from users and recover from the errors. Example run: Enter your numerator: 4.6 Invalid input, enter whole numbers only! Enter your numerator: -9 Enter your denominator: 45 The lowest terms of your fraction: -1/5 Do you want to do another conversion? (0-no, 1-yes): 1 Enter your numerator: 8 Enter your denominator: abc8 Invalid input, enter whole numbers only! Enter your denominator: 0 Invalid input, denominator cannot be 0! Enter your denominator: 2 The lowest terms of your fraction: 4 Do you want to do another conversion? (0-no, 1-yes): 0 Required function(s): Your program must involve the following functions. You may not change the parameters or the return type!!! 1 //return false if denominator is 0, return true otherwise //Reduce both numerator and denominator to lowest terms inside the function bool to_lowest_terms(int &numerator, int &denominator); OR bool to_lowest_terms(int *numerator, int *denominator); //return the greatest common divisor of num1 and num2 int g_c_d(int num1, int num2); - this must be a recursive function, and you will need to explain the algorithm during demo Note: If you use an algorithm that requires a third parameter, that is also fine.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
