1. ## Writing your own functions

Alright everyone check this out I'm a first year programming student and were in the chapter where we are required to write our own functions. Well the book we have is kind enough to give us functions with one variable
example.#include <stdio.h>

double tempvert(double);

int main()

{
int count;
double fahren;
for (count = 1; count <= 4; ++count)
{
printf("enter a temparature\n");
scanf("%lf", &fahren);
printf("the celsius equivilent is %6.2lf\n", tempvert(fahren) );
}
return 0;
}
double tempvert(double fahren)
{
return ( (5.0 / 9.0 * (fahren - 32) ));
}

but unfortunatley they neglect to give us any examples of writing your own function which would contain two variables. So basically I've been left out to dry by the book. I tried working it out logically and it just isn't making any sense does anyone out there have an example using two variable prewritten functions

2. >>but unfortunatley they neglect to give us any examples of writing your own function which would contain two variables

you mean a function that will receive as parameter two variables? well, it's easy... look at the prototype, this function will receive 2 integers, and return their sum.

Code:
```int add (int a, int b) {
return (a+b);
}```

3. ## exactly

Thats exactly what I'm talkin about the only problem is now I just need to see one simple program that adds or subtracts two numbers utilizing a user written function and I'm homefree

Code:
```#include <stdio.h>

int getSum(int a, int b)
{
return a+b;
}

int getDif(int c, int d)
{
return c-d;
}

int main()
{
printf("3+5 = %d\n", getSum(3,5));
printf("3-5 = %d\n", getDif(3,5));

return 0;
}```

5. Originally posted by Vber
>>but unfortunatley they neglect to give us any examples of writing your own function which would contain two variables

you mean a function that will receive as parameter two variables? well, it's easy... look at the prototype, this function will receive 2 integers, and return their sum.

Code:
```int add (int a, int b) {
return (a+b);
}```
Code:
```#include <stdio.h>

int add (int a, int b) {
return (a+b);
}

int main(void) {
printf("The sum of 4 and 5 is %d\n",4,5,add(4,5));
return 0;
}```

6. ## I've almost got it

Thats exactly what I'm talking about, how about one with two scanf statement

7. Homework is fun.

Code:
```#include <stdio.h>

int getSum(int a, int b)
{
return a+b;
}

int getDif(int c, int d)
{
return c-d;
}

int main()
{
int n1, n2;

printf("Enter num1: ");
scanf("%d", &n1);

printf("Enter num2: ");
scanf("%d", &n2);

printf("%d + %d = %d\n", n1, n2, getSum(n1, n2));
printf("%d - %d = %d\n", n1, n2, getDif(n1, n2));

return 0;
}```

8. ## Re: I've almost got it

Originally posted by drdodirty2002
Thats exactly what I'm talking about, how about one with two scanf statement
how about you do your own-homework? bahh doing homework for other people it's not fun.

9. ## I wish

I wish this answered my homework but unfortunatley the question that I have for my homework is alot more complex than that