• 09-24-2008
liljp617
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.

Code:

```#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("&#37;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```
My compile error is

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.
• 09-24-2008
nonoob
Yes, you have to write those functions add(), subtract(), etc. I think you've started doing that with the add() function - but it's embedded inside the case statement. You need to move that code outside of the main(). At the top I would put them. Then they act as prototypes and you don't have a need for the prototype statements. Or you can place the functions AFTER the main. Then you DO need the prototype statements.
Code:

```int add (int iFirstDigit, int iSecondDigit)               {                   return iFirstDigit + iSecondDigit;               } int subtract... int main() {        ...```
• 09-24-2008
liljp617
Thank you thank you :)

So simple -.-