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;
}


	
}

A couple suggestions (hint: they're all interrelated):
1. Add a bool variable (perhaps called "quit").
2. Convert menu() to return something other than void
3. Add a switch case
4. Figure out how to keep calling menu() as long as the user wants to

Those should start you in the right direction, the rest is up to you.

Remember, whenever you want a program to run again, without closing after its done, the majority of the program's structure must be contained within an outer loop. (This does not mean flooding main() with statements better placed elsewhere in the program.)

Add another choice to menu() that lets the user exit the program, and place the whole function into an appropriate loop. The loop should check to see that the 'exit' choice has/hasn't been selected.

Add another choice to menu() that lets the user exit the program, and place the whole function into an appropriate loop. The loop should check to see that the 'exit' choice has/hasn't been selected.

I went with your idea of adding an extra choice in the menu function, it was so simple cant beleive i didnt think of it X_X. Just hope my maths right..although not to sure, teacher gave us the formulas, hope shes right knowing her though she gave us the wrong ones XD
Thanks agian guys.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.