Static for C++

Write a C++ program that allows user to perform addition or subtraction continuously until the user decides to exit the program. Keep a counter in each of them to accumulate times the function is called

Can someone please help me with this. I have no idea where to start. I just need someone to explain to me what I need to do.

For example, I know I am suppose to have a function for both Addition and Subtraction, but I don't understand how I can make it so it loops itself and exits when the user wants to.

For the counter, I know I am suppose to use the static function, but I don't know where I should put it. Help please?
I'm a c++ beginner,I hope it's helpful for you ;-)

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

static int additionCount=0;

int addition(int x,int y)
{
	additionCount++;
	return x+y;
}

int main()
{
	while(true)
	{
		int x;
		int y;

		cout << "Please input a number: ";
		cin>>x;
		
		cout << "Please input another number: ";
		cin >> y;
 
		cout << "Result is "<< addition(x,y) << endl;
		
		cout << "Count =" << additionCount << endl;

		cout << "Go on ? (Y/N)" << endl;

		char c;
		cin>>c;
		
		if(c!='Y' & c !='y')
		{
			return 0;
		}
	}

	return 0;
}
Last edited on
Topic archived. No new replies allowed.