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.
#include <iostream>
#include <string>
usingnamespace 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;
}