### Calculator program

Hey guys, I cannot figure out how to fix this to where it works. I am supposed to get 2 numbers then have the person choose what they want to do to the numbers. Here is the code:

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178`` ``````//Mike Karbowiak //12/24/13 //Mathematics #include #include #include #include #include using namespace std; void hello(); float menu(); float Add(float num1, float num2); float Subtract(float num1, float num2); float Multiply(float num1, float num2); float Divide(float num1, float num2); void Output(float total1); int goodbye(); int main(){ system ("Color C"); float num1; float num2; hello(); cout<< "Hello, today we are going to deal with some mathematics.\n\n"; cout<< "Please enter two numbers. (hit enter after you input the first number)\n\n"; cin>>num1; cin>>num2; float total = menu(); system("cls"); Output(total); goodbye(); return(0); } void hello() { system("Color C"); cout<<"\t\t\t*******************************\n"; cout<<"\t\t\t* *\n"; cout<<"\t\t\t* Hello, my name is Mike *\n"; cout<<"\t\t\t* *\n"; cout<<"\t\t\t* I am Lord and Master *\n"; cout<<"\t\t\t* *\n"; cout<<"\t\t\t*******************************\n" <>answer; switch(answer) { case 1: total = Add(); Output(total); //output_case = 1; break; case 2: total = Subtract(); //output_case = 2; break; case 3: total = Multiply(); //output_case = 3; break; case 4: total = Divide(); //output_case = 4; break; } return (total); } float Add(float num1, float num2) { //float num1; //float num2; float sum=0; float num = 0; sum = num1 + num2; return(sum); } float Subtract(float num1, float num2) { //float num1; //float num2; float diff=0; float num = 0; diff = num2 - num1; } float Multiply(float num1, float num2) { //float num1; //float num2; float product=0; float num = 0; product = num1 * num2; } float Divide(float num1, float num2) { //float num1; //float num2; float quotient=0; float num = 0; quotient = num2 / num1; } void Output(float total) { float answer=total; cout<<"\nYou're answer is " << answer << endl; system ("pause"); system ("cls"); } int goodbye(){ //system("cls"); int again = 1; //local variables cout<<"Do you want to run again? "; cout<<"Enter 1 for yes, 0 for no \n"; cin>>again; if(again==1) main(); if(again==0) return (0); } ``````

The errors I am getting so far are:

error C2660: 'Add' : function does not take 0 arguments
error C2660: 'Subtract' : function does not take 0 arguments
error C2660: 'Multiply' : function does not take 0 arguments
error C2660: 'Divide' : function does not take 0 arguments

You're missing the return statements to some of your functions.

On lines 83-106, what do you expect to happen? The compiler will not turn into a human and say "I suppose he wants to ask the user for two values, pass those two values to each of these function calls, and then tell the user about the returned values".

Also, what is line 154 for? There's no reason to do that.
Last edited on
the return function under the switch should return that variable (total), shouldn't it?

EDIT I'm trying different suggestions and trying to make them work.
Last edited on
Also, don't ever call the main function - it's special. Instead set up a loop in main that depends on the return value from the goodbye function.

And everyone seems to forget for division by zero.

return is not a function - it's a statement - no need for the parentheses.

Have fun!!
Topic archived. No new replies allowed.