Hello there! So I have created a project for school. I have this program running without errors. The problem is it doesn't perform the math. Any ideas or suggestions? Here is the output when ran...and the code as well.

Please choose your operator :
+ (addition)
- (subtraction)
* (multiplication)
/ (division)
Operation to perform: +

Enter the numerator for the first fraction: 2
Enter the denominator for the first fraction: 4
Enter the numerator for the second fraction: 1
Enter the denominator for the second fraction: 4

Would you like to go again?

//	********************
	#include <stdafx.h>
	#include "iostream"
	#include <cmath>
//	********************
	using namespace std;
//	*******************

//	*******************
//	Function Prototypes
//	********
	void addFractions(int& n1, int& d1, int& n2,int& d2, int& num, int& den);
	void subtractFractions(int& n1, int& d1, int& n2,int& d2, int& num, int& den);
	void multiplyFractions(int& n1, int& d1, int& n2,int& d2, int& num, int& den);
	void divideFractions(int& n1, int& d1, int& n2,int& d2, int& num, int& den);
	void menu(char operationType);
//	**End**Funtion**Prototypes****
//	******************************

//	*********************
//	Variable Declarations
//	********
	int n1 = 0,
		d1 = 0,
		n2 = 0,
		d2 = 0;
	int num;
	int	den;

	char operationType;
	char answer;
	bool finished = true;
//	*********************

//	***********
	int main( )
	{


//		*************
//		User Loop
//		****
		do
		{
		menu(operationType);
			
		cout << "Enter the numerator for the first fraction: ";
		cin >> n1;

		cout << "Enter the denominator for the first fraction: ";
		cin >> d1;

		cout << "Enter the numerator for the second fraction: ";
		cin >> n2;

		cout << "Enter the denominator for the second fraction: ";
		cin >> d2;

	switch (operationType){

	case '+': 
		addFractions(n1,d1,n2,d2,num,den);
		cout << "\nThe answer is " << num << "/" << den << endl;
		break;

	case '-':
		subtractFractions(n1,d1,n2,d2,num,den);
		cout << "\nThe answer is " << num << "/" << den << endl;
		break;

	case '*':
		multiplyFractions(n1,d1,n2,d2,num,den);
		cout << "\nThe answer is " << num << "/" << den << endl;
		break;

	case '/':
		divideFractions(n1,d1,n2,d2,num,den);
		cout << "\nThe answer is " << num << "/" << den << endl;
		break;
	}
			
  
//		***********************
//		Obtain wishes from user
//		********
		cout << endl;
		cout << "Would you like to go again?" << endl;
		cin >> answer;
		if (answer == 'n')
			finished = true;
		else (answer == 'y');
			cout << "Welcome Back!" << endl;

		} while (!finished);//userLoop
//		******************************

	return 0;
	}// Function main
//	*****************



//	*************
//	Menu Function
//	****
	void menu(char operationType) 
	{
	cout << endl;
	cout << "Please choose your operator :"<< endl;
    cout << "		+ (addition)\n"
		 << "		- (subtraction)\n"
		 << "		* (multiplication)\n"
		 << "		/ (division)\n"
		 << "Operation to perform: ";
	
    cin >> operationType;
    cout << endl;
	}//**endFunction**Menu**
//	************************

//	************
//	Add Function
//	***
	void addFractions(int& n1, int& d1, int& n2,int& d2, int& num, int& den)
	{
		num = (n1*d2 + d1*n2);
		den = (d1*d2);
	}//**end**Function**Add**
//	*************************

//	*****************
//	Subtract Function
//	********
	void subtractFractions(int& n1, int& d1, int& n2,int& d2, int& num, int& den)
	{
		num = ((n1*d2) - (d1*n2));
		den = (d1*d2);
}//**end**Function**Subtract**
//	**************************

//	*****************
//	Multiply Function
//	******** 
	void multiplyFractions(int& n1, int& d1, int& n2,int& d2, int& num, int& den)
	{	
		num = (n1*n2);
		den = (d1*d2);
	}//**end**Function**Multiply**
//	******************************

//	*****************
//	Division Function
//	********
	void divideFractions(int& n1, int& d1, int& n2,int& d2, int& num, int& den)
	{
		num = (n1*d2);
		den = (n2*d1);
	}//**end**Function**Divide**
//	****************************

Recommended Answers

All 3 Replies

You need to declare the operationType in menu as a reference.
86 the asterisks.
Remove one tab from the beginning of every line.

Ok will give it a try. The format is as my teacher likes. He uses = instead of asterisks. But I like them. Sorry if it's an eye sore to you!

If menu() returns a value, then return the value. It should be a char , not void , function.

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.