Question: CAN YOU PLEASE GUIDE ME WHY I AM GETTING THIS ERROR AND HELP FIX THE CODE Instructions * * ( Fraction calculator ) * *

CAN YOU PLEASE GUIDE ME WHY I AM GETTING THIS ERROR AND HELP FIX THE CODE
Instructions
**(Fraction calculator)**| Write a program that lets the user perform arithmetic operations on fractions. Fractions are of the form a/b, in which a and b are integers and b 0. Your program must be menu driven, allowing the user to select the operation (+,,*, or /) and input the numerator and denominator of each fraction. Furthermore, your program must consist of at least the following functions:
Function menu: This function informs the user about the programs purpose, explains how to enter data, and allows the user to select the operation.
Function addFractions: This function takes as input four integers representing the numerators and denominators of two fractions, adds the fractions, and returns the numerator and denominator of the result. (Notice that this function has a total of six parameters.)
Function subtractFractions: This function takes as input four integers representing the numerators and denominators of two fractions, subtracts the fractions, and returns the numerator and denominator of the result. (Notice that this function has a total of six parameters.)
Function multiplyFractions: This function takes as input four integers representing the numerators and denominators of two fractions, multiplies the fractions, and returns the numerators and denominators of the result. (Notice that this function has a total of six parameters.)
Function divideFractions: This function takes as input four integers representing the numerators and denominators of two fractions, divides the fractions, and returns the numerator and denominator of the result. (Notice that this function has a total of six parameters.) Some sample outputs are:
**3/4+2/5=23/20**
2/3*3/5=6/15
Your answer need not be in the lowest terms.
CODE#
#include
using namespace std;
void menu(){
cout << "This program lets you perform arithmetic operations on fractions." << endl;
cout << "Enter the numerator and denominator of each fraction, separated by a space." << endl;
cout <<"To add two fractions, enter '+'"<< endl;
cout <<"To subtract two fractions, enter '-'"<< endl;
cout <<"To multiply two fractions, enter '*'"<< endl;
cout <<"To divide two fractions, enter '/'"<< endl;
cout <<"To quit the program, enter 'q'"<< endl;
}
void addFractions(int num1, int den1, int num2, int den2, int &num, int &den){
num = num1* den2+ num2* den1;
den = den1* den2;
}
void subtractFractions(int num1, int den1, int num2, int den2, int &num, int &den){
num = num1* den2- num2* den1;
den = den1* den2;
}
void multiplyFractions(int num1, int den1, int num2, int den2, int &num, int &den){
num = num1* num2;
den = den1* den2;
}
void divideFractions(int num1, int den1, int num2, int den2, int &num, int &den){
num = num1* den2;
den = den1* num2;
}
int gcd(int a, int b){
while (b !=0){
int temp = a;
a = b;
b = temp % b;
}
return a;
}
void simplifyFraction(int &num, int &den){
int gcd_value = gcd(num, den);
num /= gcd_value;
den /= gcd_value;
}
int main(){
menu();
while (true){
char operation;
cout << "Enter an operation (+,-,*,/, or q to quit): ";
cin >> operation;
if (operation =='q'){
break;
} else if (operation =='+'|| operation =='-'|| operation =='*'|| operation =='/'){
int num1, den1, num2, den2;
cout << "Enter the first fraction: ";
cin >> num1>> den1;
cout << "Enter the second fraction: ";
cin >> num2>> den2;
int num, den;
if (operation =='+'){
addFractions(num1, den1, num2, den2, num, den);
} else if (operation =='-'){
subtractFractions(num1, den1, num2, den2, num, den);
} else if (operation =='*'){
multiplyFractions(num1, den1, num2, den2, num, den);
} else if (operation =='/'){
divideFractions(num1, den1, num2, den2, num, den);
}
simplifyFraction(num, den);
cout << num1<<"/"<< den1<<""<< operation <<""<< num2<<"/"<< den2<<"="<< num <<"/"<< den << endl;
}
}
return 0;
}

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 Programming Questions!