Hey guys I overall got this problem solved it has to allow the user to input numbers to do artithmitic functions to fractions. And the whole mathmatical works fine. But the professor wants it to loop, and i cant figure out a good way to loop it. The way the functions are. Any good ideas?
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
void variable(int& a, int& b, int& c, int& d);
void addFrac(int&,int&,int&,int&,int&,int&);
void subFrac(int&,int&,int&,int&,int&,int&);
void divFrac(int&,int&,int&,int&,int&,int&);
void multiplyFrac(int&,int&,int&,int&,int&,int&);
void menu();
int main()
{
menu();
}
void variable(int& a, int& b, int& c, int& d)
{
cout << "Please enter in the first fraction numerator" << endl;
cin >> a;
cout << "Please enter in the first fraction denomator" << endl;
cin >> b;
cout << "Please enter in the second fraction numerator " << endl;
cin >> c;
cout << "Please enter in the second fraction denomator" << endl;
cin >> d;
}
void addFrac(int& a, int& b, int& c, int& d, int& num,int& den)
{
num= (a*d + b*c);
den= (b*d);
}
void subFrac(int& a, int& b, int& c, int& d, int& num,int& den)
{
num=((a*d)-(b*c));
den=(b*d);
}
void divFrac(int& a, int& b, int& c, int& d, int& num,int& den)
{
num= (a*d);
den = (b*c);
}
void multiplyFrac(int& a, int& b, int& c, int& d,int& num,int& den)
{
num=a*c;
den=b*d;
}
void menu()
{
int a;
int b;
int c;
int d;
int num;
int den;
int choice;
cout << "The Fraction Program" << endl;
cout << "Please Choose from the following possible mathmatical operations" << endl;
cout << " 1 : Will add two fractions together" << endl;
cout << " 2 : Will subtract two fractions" << endl;
cout << " 3 : Will divide two fractions" << endl;
cout << " 4 : Will multiply two fractions" << endl;
cin >> choice;
switch (choice)
{
case 1 :
variable(a,b,c,d);
addFrac(a,b,c,d,num,den);
break;
case 2 :
variable(a,b,c,d);
subFrac(a,b,c,d,num,den);
break;
case 3:
variable(a,b,c,d);
divFrac(a,b,c,d,num,den);
break;
case 4:
variable(a,b,c,d);
multiplyFrac(a,b,c,d,num,den);
break;
default:
cout << "Sorry thats an invalid choice" << endl;
}
}