I'm having a bit of trouble with a assignment.. I have to use functions to declare any type of problem done to a fraction using functions. I need a little help accomplishing this and any help would be greatly appreciated.
heres my code thus far,
#include <iostream>
#include <iomanip>
#include <sstream>
using namespace std;
bool addFrac (int n1, int n2, int d1, int d2, int e, int f)
{
e = n1*d2 + n2*d1;
f = n2*d2;
}
bool divFrac (int n1, int n2, int d1, int d2, int e, int f)
{
e = n1*d2 / n2*d1;
f = n2*d2;
cout<< n1 << "/" << d2 << " / " << n2 << "/" << d1 << " = ";
cout << e/f << " " << e%f << "/" << f << endl;
}
int main
{
int menu, f, n1, n2, d1, d2, a, b, c, d, e, f;
char prob;
const int
instruct = 1,
noinstruct = 2,
quit = 3;
const char
add = +,
sub = -,
multi = *,
divide = /;
do {
cout << " Would you like to view ? " << endl;
cout << " A short set of instructions on how to run the program ?" <<endl;
cout << "----------------------------------------------------\n";
cout << endl;
cout << " 1. View program instructions " << endl;
cout << " 2. Run program without instructions " << endl;
cout << " 2. Quit the program. " << endl;
cout << endl << endl;
cout << "Enter your Choice: ";
cin >> menu;
if ((menu < 1) || (menu > 3 ))
{
cout << endl;
cout << "The valid choices are 1 through 2. Rerun the program\n";
cout << "again and select a valid choice.\n" << endl;
system ("pause");
system("CLS");
}
}while ((menu < 1) || (menu > 3 ));
switch(menu)
{
case instruct
cout << " To use this program you will be asked to " << endl;
cout << " input two fractions and what mathimatically shall be done "
<< endl;
cout << " such as adding, subtracting, division or multiplication "
<< endl;
cout << " The program shall find the solution in its lowest form"
<< endl;
cout << "Enter the first numerator: " << n1 << endl;
cout << "Enter the first denominator: " << d1 << endl;
cout << "Enter the second numerator: " << n2 << endl;
cout << "Enter the second denominator: " << d2 << endl;
cout << "Choose the form of fraction problem" << endl;
cout << "For addition = + || for subtraction = - "
<< " for multiplication = x || for division = / " << endl;
cin << prob;
switch (prob)
{
case add
void addFrac(n1,n2,d1,d2);
break;
case sub
void subFrac;
break;
case multi
void multiFrac;
break;
case divide
void divFrac;
break;
}
case noinstruct :
cout << "Enter the first numerator: " << n1 << endl;
cout << "Enter the first denominator: " << d1 << endl;
cout << "Enter the second numerator: " << n2 << endl;
cout << "Enter the second denominator: " << d2 << endl;
cout << "Choose the form of fraction problem" << endl;
cout << "For addition = + || for subtraction = - "
<< " for multiplication = x || for division = / " << endl;
cin << prob;
switch (prob)
{
case add
void addFrac;
break;
case sub
void subFrac;
break;
case multi
void multiFrac;
break;
case divide
void divFrac;
break;
}
case Quit:
cout << "Program exiting.\n" << endl;
break;
I'm still fairly new at this so i know that I have alot of redundant code but any help would be more than appreciated