# How to use void sum

**URL:** <https://discourse.processing.org/t/how-to-use-void-sum/42321>\
**Category:** Beginners\
**Tags:** homework\
**Created:** [July 1, 2023, 10:49am UTC](https://discourse.processing.org/t/how-to-use-void-sum/42321 "2023-07-01T10:49:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Janoer](https://avatars.discourse-cdn.com/v4/letter/j/34f0e0/32.png) [@Janoer](https://discourse.processing.org/u/Janoer)\
**Post date:** [July 1, 2023, 10:49am UTC](https://discourse.processing.org/t/how-to-use-void-sum/42321/1 "2023-07-01T10:49:03Z")

</div>

Hello, I want to use sum but I don’t know where to put number. is there anything that can help? Thank You!

```auto
void sum(int a, int b, int c) {
  in total = a + b + c;
  printIn(total);
}

```

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [July 1, 2023, 10:59am UTC](https://discourse.processing.org/t/how-to-use-void-sum/42321/2 "2023-07-01T10:59:10Z")

</div>

Keyword `void` is intended for functions which don’t `return` anything.

> **[void / Reference](https://processing.org/reference/void.html)**
>
> Keyword used to indicate that a function returns no value. Each function must either return a value of a specific datatype or use the keyword void to specify it returns nothing.

> **[return / Reference](https://processing.org/reference/return.html)**
>
> Keyword used to indicate the value to return from a function. The value being returned must be the same datatype as defined in the function declaration. Functions declared with void can't retur…

For returning anything else we’ve gotta declare which datatype a function must `return`.

Here’s a **sum()** function example for the [`int`](https://processing.org/reference/int.html) primitive datatype:

```auto
static final int sum(final int... values) {
  int total = 0;
  for (final int v : values) total += v;
  return total;
}

```

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [July 1, 2023, 11:11am UTC](https://discourse.processing.org/t/how-to-use-void-sum/42321/3 "2023-07-01T11:11:21Z")

</div>

Based on your post and avoiding advanced syntax you can do

```auto
// Calculate the sum of 3, 4 and 5
int total = sum(3, 4, 5);

int sum(int a, int b, int c){
  return a + b + c;
}

```

---

<div class="post-metadata">

**Author:** ![Janoer](https://avatars.discourse-cdn.com/v4/letter/j/34f0e0/32.png) [@Janoer](https://discourse.processing.org/u/Janoer)\
**Post date:** [July 1, 2023, 11:49am UTC](https://discourse.processing.org/t/how-to-use-void-sum/42321/4 "2023-07-01T11:49:05Z")

</div>

Thank you for the help!!

---

<div class="post-metadata">

**Author:** ![Janoer](https://avatars.discourse-cdn.com/v4/letter/j/34f0e0/32.png) [@Janoer](https://discourse.processing.org/u/Janoer)\
**Post date:** [July 1, 2023, 11:54am UTC](https://discourse.processing.org/t/how-to-use-void-sum/42321/5 "2023-07-01T11:54:49Z")

</div>

thank you for the explanation!
