Sum of positive numbers

Hey, I'm trying to make a code where the user inputs a series of positive numbers and when they input a negative number, the series stops and adds all the positive numbers that were entered in. The program keeps displaying that the sum of all the positive numbers is 0 whenever I run it. I'm still a beginner at this and I've tried a lot of things with this code so I could use some help with this.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
  #include <iostream>
#include <string>

using namespace std;
 void getTotalSum (
       int totalSum)
{
   
   int inputNumber;
   

   inputNumber =0;
   while (1)
   {
      cout << "Enter a series of numbers  or a negative number  to stop" << endl;
      cin >> inputNumber;
      if (inputNumber>0)
      {
         totalSum = totalSum + inputNumber;
      }
      else
      {
      }
      if (inputNumber<0) break;
   }
}
 void displayTotalSum (
       int totalSum)
{
   

   cout << "The sum of this series is " << totalSum << endl;
   }
int main()
{
   int totalSum;

   totalSum=0;
   getTotalSum(totalSum);
   displayTotalSum(totalSum);

   return 0;
}
Your function arguments as by value; mere copies. Have you read about by reference function arguments?
I think I might have read about that at some point, I'll go look that up when I have the chance. Thanks for the advice.
Topic archived. No new replies allowed.