### 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.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134`` ``````#include 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:
 ``12`` ``````//Prototype from beginning of file void operations(int choice,int& numerator1, int& denominator1, int& numerator2, int& denominator2, int& new_numberator, int& new_denominator) ;``````

 ``1234`` ``````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.
 ``1234`` ``````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.