CSCI 116
Programming Project #11
You are to
write a fraction calculator that doesn’t use decimal approximations to do the
computation. Your program should represent
the fractions as structures containing two integers, the numerator and the
denominator, and should express all results as reduced fractions. Each fraction should be printed as an integer
part and a proper fraction if it is greater than or equal to one, instead of as
an improper fraction. Your program
should read in two fractions and an operation, perform that operation, and
print the result. It should then loop
until the user enters zero over zero as the first fraction, and then exit. You should have separate functions to add two
fractions, subtract two fractions, multiply two fractions, and divide two
fractions, as well as to print a fraction.
You should use the GCD function that we wrote in class to assist you in
simplifying fractions.
Here is a
sample output from the program:
Enter fraction calculation to perform:
1/2 + 3/4
The answer is 1 1/4
Enter fraction calculation to perform:
1/2 – 3/4
The answer is -1/4
Enter fraction calculation to perform:
1/2 * -3/4
The answer is -3/8
Enter fraction calculation to perform:
1/2 / -3/4
The answer is -2/3
Enter fraction calculation to perform:
0/0 + 1/2
Press any key to continue
You should do
error checking to make sure that none of the calculations would require
division by zero, and print out an appropriate error when that occurs.