Basic Program Help

I'm at a loss, I can't for the life of me understand what this question is asking, and my assumption was that it wanted a series of numbers input and a function to keep a running total. My head is a bit in the clouds today so this might just be me making a stupid mistake, the question is as follows:

"Using a static integer variable, sum, in a function called AddUp(), keep a running total of values passed by repeated calls to the function. After each call to the function, add the value passed in to sum and return and display sum in main()."

And so far I'm staring at something that I'm aware doesn't make sense, but I don't know what to do


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
#include <iostream> //allows program to input and output data
#include <iomanip>
using namespace std;


          int value;
          int result;
          
int main () //Begins program execution
{ 
     int value; 
     int result; 
     

     result = 0; 
     
     cout << "Enter value or -1 to quit: ";
     cin >> value; 
     
     
     cin >> value;
     while(value != 0)
     {
          result = AddUp(value);
          cout << result;
          cin >> value;
     }
     
     system ("pause");
     return 0;
}

function addup()
    {
           cin >> value;
           value + result = result;
    }

Something like this :

1
2
3
4
5
int AddUp(int i) {
static int sum=0;
sum+=i;
return sum;
}
Edit: that helps but I still don't really know what to do
Last edited on
Here:

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
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;

int Addup(double input, double sum)
{
    sum += input;
    return sum;
}

int main(int nNumberofArgs,char* pszArgs[])
{
    double sum = 0;
    double input = 0;
    cout << "This is an addition program, enter  to quit" << endl;

    for(;;)
    {
        cout << "Next number: ";
        cin >> input;

        if(input == 0)
        {
            cout << "The sum of those numbers is: " << sum << endl;
            system("PAUSE");
            return 0;
        }
        sum = Addup(input,sum);
    }
}
I am suppose to write an assignment statement for this operation......

1.) Stores the ASCII code for 'B' in e

I came up with e= char 66

Can someone help me please?
Wow, thank you! I was stressing so much I think I get it now I don't know why I tripped so hard over that :D
Topic archived. No new replies allowed.