String Subsript error.

I'm getting a string subscript error. Just can't seem to figure out what it is? can someone please help me find the error. Would highly appreciate it and the error does happen at the runtime.

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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
  void addnumber_formula(string one,string two, int result[],int resultsize)
{
	//Declare sum to store the sum of indexes
	int sum=0;
	int lastnum=0;
	int carry=0;
	int row=0;
	int counter;

	//find the length of each string.
	int length1, length2;
	int max;
	length1=one.length();
	length2=two.length();
	//Determine which one of these is a max

	if (length1>length2)
		max=length1;
	else
		max=length2;

	//make a for loop to get each letter of a string
	for (counter=one.length();counter>0;counter--)
	{
		sum=(one[counter]-'0')+(two[counter]-'0')+carry;
		
		//Find the last number of sum
		lastnum=sum%10;

		//find first number of sum
		carry=sum/10;

		//store last number in the result
		result[row]=lastnum;
		row++;
		//if max is equal to one then make sure to enter carry in the array
			if (counter==1)
			{
				
				result[row]=carry;
			}
			
	}


}

void print_addition(int result[],int size)
{
	for (size;size>0;size--)
		cout<<result[size];

}

int _tmain(int argc, _TCHAR* argv[])
{
	 
	//Cal he function to get the twenty digit number
	string one,two;
	display(one, two);
	int results[4];

	

	//Call addnumberformula
	addnumber_formula(one, two, results,4);
also I'm using "4304" and "3321" as my sample numbers
Alright I got it fixed :D
Topic archived. No new replies allowed.