1. ## code help :)

I have made a calculator for my homework, but am having a few problems.

Here is what I have in main.c:

Code:
```/************************************************************
Filename:	main.c
Author:		Mike Hartwig(mike.hartwig@attbi.com)
Input:		Keyboard
Output:		Monitor
*************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "functions.h"

int main()
{
int data1 = 0;
int data2 = 0;
char sign = '_';
char pcsign = '%';

{
printf("\n*************Calculator*************\n");
printf("Data 1:	    %d\n", data1);
printf("Data 2:     %d\n", data2);
printf("Operator:   %c\n", sign);
printf("************************************\n");
printf("1)Set Data 1 \n");
printf("2)Set Data 2 \n");
printf("3)Set Operator +\n");
printf("4)Set Operator -\n");
printf("5)Set Operator *\n");
printf("6)Set Operator /\n");
printf("7)Set Operator %c\n", pcsign);
printf("8)Set Operator pow\n");
printf("9)Set Operator exp\n");
printf("10)Set Operator sqrt\n");
printf("11)Set Operator sin\n");
printf("12)Quit");

{
case 1:
{
printf("Enter Data 1: ");
scanf("%d", &data1);
break;
}
case 2:
{
printf("Enter Data 2: ");
scanf("%d", &data2);
break;
}
case 3:
{
sign = '+';
break;
}
case 4:
{
sign = '-';
break;
}
case 5:
{
sign = '*';
break;
}
case 6:
{
if (data1 == 0 || data2 == 0)
{
printf("\nCan't Divide By Zero\n");
}
else
{
sign = '/';
}
break;
}
case 7:
{
if (data1 == 0 || data2 == 0)
{
printf("\nCan't Divide By Zero\n");
}
else
{
sign = '%';
}
break;
}
case 12:
{
return(0);
}

default:
{
break;
}
}
}
return (0);
}```
Here is what I have in functions.c
Code:
```#include <stdio.h>
#include <stdlib.h>
#include "functions.h"
/*****************************************************
******************************************************/
{
printf("\nCalculating...\n");
}

/*****************************************************
Function Name:	sub()
Purpose:		Subtracts data1 and data2
******************************************************/
int sub(int data1, int data2)
{
printf("Calculating...\n");
}

/*****************************************************
Function Name:	mult()
Purpose:		Multiplies data1 and data2
******************************************************/
int mult(int data1, int data2)
{
printf("\nCalculating...\n");
}

/*****************************************************
Function Name:	div()
Purpose:		Divides data1 and data2
******************************************************/
int divide(int data1, int data2)
{
printf("\nCalculating...\n");

}

/*****************************************************
Function Name:	pcent()
Purpose:		Divides data1 and data2
******************************************************/
int pcent(int data1, int data2)
{
printf("\nCalculating...\n");
}```
The default function is supposed to be addition, but i am not exactly sure of how to do this. Also when the user enters in a new value intop one of the data varialbes, it is supposed to update the answer, but it doesnt. It only updates the answer if you set the operator again.

2. Try this:
Code:
```int main()
{
int data1 = 0;
int data2 = 0;
char sign = '+';
char pcsign = '%';

{
printf("\n*************Calculator*************\n");
printf("Data 1:	    %d\n", data1);
printf("Data 2:     %d\n", data2);
printf("Operator:   %c\n", sign);
printf("************************************\n");
printf("1)Set Data 1 \n");
printf("2)Set Data 2 \n");
printf("3)Set Operator +\n");
printf("4)Set Operator -\n");
printf("5)Set Operator *\n");
printf("6)Set Operator /\n");
printf("7)Set Operator %c\n", pcsign);
printf("8)Set Operator pow\n");
printf("9)Set Operator exp\n");
printf("10)Set Operator sqrt\n");
printf("11)Set Operator sin\n");
printf("12)Quit");

{
case 1:
{
printf("Enter Data 1: ");
scanf("%d", &data1);
break;
}
case 2:
{
printf("Enter Data 2: ");
scanf("%d", &data2);
break;
}

case 3:
{
sign = '+';
break;
}
case 4:
{
sign = '-';
break;
}
case 5:
{
sign = '*';
break;
}
case 6:
{
sign = '/';
break;
}
case 7:
{
sign = '%';
break;
}
case 12:
{
return(0);
}

default:
{
break;
}
}
switch (sign)
{
case '+':
{
break;
}
case '-':
{
break;
}
case '*':
{
break;
}
case '/':
{
if (data1 == 0 || data2 == 0)
{
printf("\nCan't Divide By Zero\n");
}
else
{
}
break;
}
case '%':
{
if (data1 == 0 || data2 == 0)
{
printf("\nCan't Divide By Zero\n");
}
else
{
}
break;
}
}
}
return (0);
}```

3. works great thanks m8. You are my saviour.

4. i finally got around to coding the sqrt, exp and pow functions. The only thing wrong with that, is i catn have the sign as sqrt or anything, cuz the compiler thinks its a math function. And there arentand specifics operator symbols for those functions.

5. You probably need to change 'sign' to a character array, so you can store something like "sqrt" or "sin" for your display. If you do this, you will have to use strcpy() from <string.h> to assign to the variable 'sign': strcpy(sign,"+") or strcpy(sign,"sin").

If you use a character array, you will not be able to use a switch() statement with 'sign', as I think switch() only works for one char. Either use if-then-else, or create a second variable. If you create a second variable, then choose one character to associate with each function: for example, for sin(), 's'.