Need help with my homework.

I get the following error in my switch within the operations function
Error: more than one instance of overloaded function "multiplication" matches the argument list. it does this for cases 1 through 4. not sure what I am doing wrong. your user id will be used to give credit for helping.

the program adds, subtracts, multiplies, or divides fractions. here is my code. I have to use functions for everything.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include<iostream>

using namespace std;
 
// function prototypes
void intro() ;
void menu(int choice) ;
void get_fractions(int numerator1,int denominator1,int numerator2,int denominator2) ;
void addition(int& numerator1, int& denominator1, int& numerator2, int& denominator2, int& new_numberator, int& new_denominator) ;
void subtraction(int& numerator1, int& denominator1, int& numerator2, int& denominator2, int& new_numberator, int& new_denominator) ;
void multiplication(int& numerator1, int& denominator1, int& numerator2, int& denominator2, int& new_numberator, int& new_denominator) ;
void division(int& numerator1, int& denominator1, int& numerator2, int& denominator2, int& new_numberator, int& new_denominator) ;
void operations(int choice,int& numerator1, int& denominator1, int& numerator2, int& denominator2, int& new_numberator, int& new_denominator) ;




int main()
{

	int choice, numerator1, denominator1, numerator2, denominator2, new_numberator, new_denominator ;
	
	intro() ;
	menu(choice) ; 
	get_fractions(numerator1, denominator1, numerator2, denominator2) ; 
	operations(choice, numerator1, denominator1, numerator2, denominator2, new_numberator, new_denominator) ;
	
	
	system("PAUSE") ;
	return 0;
 } // Close main
 

// functions
void intro()
{
	cout << "This program will add, multiply, subtract or divide fractions." << endl
		 << endl ;
}

void menu(int choice)
{
	
	cout << " What arithmetic operation would you like to perform?" << endl << endl ; 
	
	cout << " 1.) Multiplication" << endl
		 << " 2.) Division" << endl 
		 << " 3.) Addition" << endl 
		 << " 4.) Subtraction" << endl << endl ;
		 
	cout << " Please enter menu number for operation desired: ";
	cin >> choice ; 
	
} // End menu function

void get_fractions(int numerator1,int denominator1,int numerator2,int denominator2)
{

	char throw_away;
 
	cout<<"Please enter your first fraction. Example 1/2: " ;
	cin >> numerator1 >> throw_away >> denominator1 ;
	
	cout<<"Please enter your second fraction. Example 1/2: " ;
	cin >> numerator2 >> throw_away >> denominator2 ;
 
} // close fractions function

void addition(int numerator1, int denominator1, int numerator2, int denominator2, int new_numberator, int new_denominator) //function prototype for adding
{
	new_numberator = (numerator1 * denominator2) + (numerator2 * denominator1) ;
	
	new_denominator = denominator1 * denominator2 ;
 
	cout << new_numberator << "/" << new_denominator ;
 } // close addition function

void subtraction(int numerator1, int denominator1, int numerator2, int denominator2, int new_numberator, int new_denominator)//function prototype for adding
{
	new_numberator = (numerator1 * denominator2) - (numerator2 * denominator1) ;
	
	new_denominator = denominator1 * denominator2 ;
 
	cout << new_numberator << "/" << new_denominator ;
 } // close subtraction function

void multiplication(int numerator1, int denominator1, int numerator2, int denominator2, int new_numberator, int new_denominator)//function prototype for adding
{
	new_numberator = numerator1 * numerator2 ;
	
	new_denominator = denominator1 * denominator2 ;
 
	cout << new_numberator << "/" << new_denominator ;
 } // close multiplication function

void division(int numerator1, int denominator1, int numerator2, int denominator2, int new_numberator, int new_denominator)//function prototype for adding
{
	// this takes the first fraction and multiplys it by the reciprical of the second fraction
	
	new_numberator = numerator1 * denominator2 ;
	
	new_denominator = denominator1 * numerator2 ;
 
	cout << new_numberator << "/" << new_denominator ;
 } // close division function

void operations(int choice,int numerator1, int denominator1, int numerator2, int denominator2, int new_numberator, int new_denominator)
{ 
	switch(choice) //switch statement that allows user to enter a choice
	{
		case 1: multiplication(numerator1, denominator1, numerator2, denominator2, new_numberator, new_denominator) ;
		
			break;
		
		case 2: division(numerator1, denominator1, numerator2, denominator2, new_numberator, new_denominator) ;
		
			break;
		
		case 3: addition(numerator1, denominator1, numerator2, denominator2, new_numberator, new_denominator) ;
		
			break;
		
		case 4: subtraction(numerator1, denominator1, numerator2, denominator2, new_numberator, new_denominator) ;
		
			break;
 
		default:
		
			cout << "Please enter a vailid operation." ;
		
			break;

	} // closes switch
 } // closes operation function 
Last edited on
Don't post homework questions
Programmers are good at spotting homework questions; most of us have done them ourselves. Those questions are for you to work out, so that you will learn from the experience. It is OK to ask for hints, but not for entire solutions.


Please refer to this http://www.cplusplus.com/forum/beginner/1/ read before posting article.
Check your prototypes against your definitions! Your prototypes have a bunch of pass-by-reference parameters, but your function definitions don't have any parameters that are passed by reference. Essentially you are declaring two different functions and the compiler can't tell them apart based on the parameters you pass when you call them. Take operations for example:
1
2
//Prototype from beginning of file
void operations(int choice,int& numerator1, int& denominator1, int& numerator2, int& denominator2, int& new_numberator, int& new_denominator) ;

1
2
3
4
void operations(int choice,int numerator1, int denominator1, int numerator2, int denominator2, int new_numberator, int new_denominator)
{
//...code...
}

You need to change the second declaration to take reference parameters, as well.
1
2
3
4
void operations(int choice,int& numerator1, int& denominator1, int& numerator2, int& denominator2, int& new_numberator, int& new_denominator)
{
//...code...
}
Last edited on
Please paste your code in between these tags and update your first post:

["code"]["/code"]

No quotes
Last edited on
@ Bourgond Aries I did not post a homework question, I posted the code I came up with for my homework and I posted the problem that I was having and where the problem was. I also stated what my code was ment to do.
@ booradley60 thanks for the insight took a look at what I did and you are right. I corrected my mistake and Its running but with some issues. time to work on those. thank you very much. I will use your screen name to give credit for help recieved on my assignment.
Topic archived. No new replies allowed.