Question
Can someone explain how my code is wrong this is for C++. I'm missing addFractions and as well the last one please help. (Fraction calculator)
Can someone explain how my code is wrong this is for C++. I'm missing addFractions and as well the last one please help.
(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.
#include using namespace std; void menue(char&,int&,int&, int&, int&); void addFraction(int,int, int, int, int&, int&); void subtractFractions(char,int,int, int, int, int&, int&); void multiplyFractions(char,int,int, int, int, int&, int&); void divideFractions(char,int,int, int, int, int&, int&); int gethcf(int,int); void simplify(int&,int&); bool wishContinue(int&); int main() { int n1=0; int n2=0; int n3=0; int d1=0; int d2=0; int d3=0; int result=0; char operation; char slash='/'; menue(operation,n1,n2, d1, d2); if(operation == '+') addFraction(n1,n2, d1, d2, n3, d3); else if(operation == '-') subtractFractions(operation,n1,n2, d1, d2, n3, d3); else if(operation == '*') multiplyFractions(operation,n1,n2, d1, d2, n3, d3); else if(operation == '/') divideFractions(operation,n1,n2, d1, d2, n3, d3); cout << n3 << slash << d3 << endl; return 0; } void simplify(int& numerator, int& denominator) //Euclids algorithm { int a,b; a=numerator; b=denominator; while(a!=b) {if(a>b) a -= b; else b -= a; } numerator/=a; denominator/=a; } void menue(char& operation,int& n1,int& n2,int& d1,int&d2) { cout << "This programm calacualte the fraction" << endl; cout << "select one of the following operation,(+ ,- ,*,/)" << endl; cin >> operation; while (operation != '+' && operation!= '/' && operation != '*' && operation != '-') { cout << "You enter the wrong operator , select one of the following operation,(+ ,- ,*,/)" < cin >>
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started