debug error

a debug error pop up when output the result

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

int addition(int a,int b,int g=0)
{
	int c;
	g+=1;
		c=a+b*g;
	return (c);
}
int main ()
{
int e,a,b,n,g;
cout<<"Pleae enter the  number of numbers of the sequetial: ";
	//لادخال عدد حدود المتتابعة
	cin>>n;
	cout<<"Pleas enter first number of the sequential: ";
		//لادخال ا
		cin>>a;
	cout<<"Pleas enter the basic of sequential: ";
	//لادخال د
	cin>>b;
	// الحد العام
	e=addition(a,b,g);
	for(int z=0;z<=n;z++)
	{
	cout<<e;
	}
	return 0;
}
I think it's because g has an invalid value. Initializing it to 0 might solve the problem.

But stating the error would help a lot.

Aceix.
Topic archived. No new replies allowed.