I know there's a million of these but I've been trying to work through it for a while and can't grasp it.
Basically have to make a calculator using functions for the basic mathematical operations.
Here's a small bit of my code, and I'm getting the same error for each of my switch statements so one answer should work for all.
My compile error isCode:#include <stdio.h> #include <stdlib.h> int add(int, int); //addition function prototype int subtract(int, int); //subtraction function prototype int multiply(int, int); //multiply function prototype int divide(int, int); //divide function prototype int modulus(int, int); //modulus function prototype int primeNumber(int); //test prime function prototype int power(int, int); //exponent function prototype int factorial(int); //factorial function prototype int main() { /*Declare/Initialize Variables*/ int iSelection = 0; //Menu selection int iFirstDigit = 0; //First digit entered int iSecondDigit = 0; //Second digit entered while (iSelection !=10) { /*Begin Calculator*/ printf("\n Calculator\n\n"); printf("1 Addition\n"); printf("2 Subtraction\n"); printf("3 Multiplication\n"); printf("4 Division\n"); printf("5 Modulus (Integers Only)\n"); printf("6 Test If Prime (Integers Only)\n"); printf("7 Factorial (Integers Only)\n"); printf("8 Power\n"); printf("10 Exit Calculator\n"); /*Prompt User To Begin Interaction*/ printf("\nPlease select one of the options (1-7): "); scanf("%d", &iSelection); switch(iSelection) //begin switch { case 1: printf("\nPlease enter first digit to be added: "); scanf("%d", &iFirstDigit); printf("\nPlease enter second digit to be added: "); scanf("%d", &iSecondDigit); printf("\nThe sum of the two numbers is %d\n\n", add(iFirstDigit, iSecondDigit)); int add (int iFirstDigit, int iSecondDigit) { return iFirstDigit + iSecondDigit; } break; //end case 1
[Linker error]: undefined reference to 'add'
I'm assuming it has something to do with how I've defined/prototyped my function or something along those lines, but I can't spot the error myself.
I've looked through past threads of this nature and couldn't really find the solution. Any help at all is appreciated.



LinkBack URL
About LinkBacks


