Ok, so I am writing a calculator program for class, but I keep getting an error that says:
 ``12`` ``````Calculator.cpp: In function 'int main()': Calculator.cpp:40: error: 'multiply' was not declared in this scope``````

I am confused... divide works, not multiply though. Some help please?

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107`` ``````/* Luke Lyon Assignment 5 Section 2 10-1-2012 */ #include #include using namespace std; //---------- Function Prototypes ----------- void print_menu(); float get_value(); float divide(float,float); //-------------- Main ------------------- int main() { float operand1, operand2, answer; int choice, valid_choice; do{ print_menu(); cin >> choice; valid_choice = 1; // assume choice is valid switch(choice){ case 0: break; case 1: operand1 = get_value(); operand2 = get_value(); answer = operand1 + operand2; break; case 2: operand1 = get_value(); operand2 = get_value(); answer = operand1 - operand2; break; case 3: operand1 = get_value(); operand2 = get_value(); answer = multiply(operand1,operand2); break; case 4: operand1 = get_value(); operand2 = get_value(); answer = divide(operand1,operand2); break; case 5: operand1 = get_value(); operand2 = get_value(); answer = 3.14159 * (pow(operand1,2)) * operand2; break; case 6: operand1 = get_value(); answer = divide(4,3) * 3.14159 * (pow(operand1,3)); break; case 7: operand1 = get_value(); answer = pow(operand1,3); break; default: valid_choice = 0; cout << "Invalid Choice." << endl; } if(valid_choice){ cout << endl << "Answer = " << answer << endl; } }while(choice != 0); return 0; } //-------------- Functions ------------------- float divide(float dividend, float divisor){ if(divisor == 0) return 0; // avoids divide by zero errors else return (dividend/divisor); } float multiply(float multi, float multiplier){ return (multi*multiplier); } float get_value(){ float temp_value; cout << "Enter a value: "; cin >> temp_value; return temp_value; } void print_menu(){ cout << endl; cout << "Add (1)" << endl; cout << "Subtract (2)" << endl; cout << "Multiply (3)" << endl; cout << "Divide (4)" << endl; cout << "Volume of a Right Cylinder (5)" << endl; cout << "Volume of a Sphere (6)" << endl; cout << "Volume of a Cube (7)" << endl; cout << "Exit (0)" << endl; cout << "Enter you choice: "; } ``````
You did neither declare the function prototype of multiply at the function prototype section nor did you provide the implementation of multiply before the calling function, so multiply is unknown when the compiler parses the main function
You're missing the prototype for it.

multiply has to be declared before main calls it. This means either moving the function so it's above main, or making a prototype for it.
Oh crap, thanks guys, haha. My bad
Topic archived. No new replies allowed.