My arrays are showing errors

My teacher gave us a program in visual basic and I've decided to convert it into C++ as practice. I've converted as best i can, not changing the way that she did it (whilst holding myself back) because she would get angry.
Anyways for some reason, the arrays i have passed in to the different functions are not working and i don't understand the error message I am presented with.

This is the code i converted:
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include <iostream>
#include <string>

using namespace std;

typedef unsigned short int ushort;

void enter_data(string list_data[12], ushort list_ptr[12], ushort& start, ushort& no_of_recs);
void print_list(string list_data[12], ushort list_ptr[12], ushort start, ushort no_of_recs);

int main()
{
	ushort pointer[12], start_rec, records;
	string data[12];
	records = 0;

	enter_data(data, pointer, start_rec, records);
	print_list(data, pointer, start_rec, records);
	enter_data(data, pointer, start_rec, records);
	print_list(data, pointer, start_rec, records);

	return 0;
}

void print_list(string list_data[12], ushort list_ptr, ushort start, ushort no_of_recs)
{
	//print out linked list so far
	cout<<start<<endl;

	for(int i = 1; i == no_of_recs; ++i)
	{
		cout<<i<<" "<<list_data(i)<<" "<<list_ptr(i)<<endl;
	}
}

void enter_data(string list_data, ushort list_ptr, ushort& start, ushort& no_of_recs)
{
	ushort ptr, ptr2, prev_ptr;
	bool flag;
	string new_data;

	if(no_of_recs == 0)
	{
		start = 1;
		ptr =0;
	}
	else
	{
		ptr = no_of_recs;
	}

	do
	{
		flag = false;
		ptr += 1;

		cout<<"Enter Data";

		cin>>new_data;
		no_of_recs += 1;

		if(new_data != "XXX")
		{
			list_data(ptr) = new_data;
			list_ptr(ptr) = 0;

			if(ptr != 1)
			{
				//if ptr = 1 then there is no more data to check
				if((list_data(ptr)) < (list_data(start)))
				{
					//the new ddata needs to be added at the start of the linked list
					list_ptr(ptr) = start;
					start = ptr;
				}
				else
				{
					ptr2 = start;
					do
					{
						if((list_data(ptr)) < (list_data(ptr2)))
						{
							list_ptr(prev_ptr) = ptr;
							list_ptr(ptr) = ptr2;
							flag = true;
							//insert data into middle of list
						}
						else
						{
							if(list_ptr(ptr2) == 0)
							{
								list_ptr(ptr2) = ptr;
								flag = true;
								//add record at the end
							}
							else
							{
								prev_ptr = ptr2;
								ptr2 = list_ptr(ptr2);
							}
						}
					}while(flag != true);
				}
			}
		}
	}while(new_data != "XXX");
	no_of_recs -= 1;
}


Here is my teachers VB original:
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
Module Module1
    Sub enterdata(ByRef listdata, ByRef listptr, ByRef start, ByRef noofrecs)
        Dim ptr, ptr2, prevptr As Byte
        Dim flag As Boolean
        Dim newdata As String
        If noofrecs = 0 Then
            start = 1
            ptr = 0
        Else
            ptr = noofrecs
        End If

        Do

            flag = False
            ptr = ptr + 1
            Console.WriteLine("enter data")

            newdata = Console.ReadLine()
            noofrecs = noofrecs + 1
            If newdata <> "XXX" Then

                listdata(ptr) = newdata
                listptr(ptr) = 0
                If ptr <> 1 Then
                    'if ptr = 1 then there is no more data to check
                    If listdata(ptr) < listdata(start) Then
                        'the new data needs to be added at the start of the linked list
                        listptr(ptr) = start
                        start = ptr

                    Else
                        ptr2 = start
                        Do
                            If listdata(ptr) < listdata(ptr2) Then

                                listptr(prevptr) = ptr
                                listptr(ptr) = ptr2
                                flag = True
                                'insert data into middle of list
                            Else
                                If listptr(ptr2) = 0 Then
                                    listptr(ptr2) = ptr
                                    flag = True
                                    'add record at the end
                                Else
                                    prevptr = ptr2
                                    ptr2 = listptr(ptr2)
                                End If
                            End If
                        Loop Until (flag = True)
                    End If
                End If
            End If
        Loop Until newdata = "XXX"
        noofrecs = noofrecs - 1
    End Sub
    Sub printlist(ByVal listdata, ByVal listptr, ByVal start, ByVal noofrecs)

        'print out linked list so far
        Console.WriteLine(start)
        For count = 1 To noofrecs


            Console.WriteLine(count & " " & listdata(count) & "  " & listptr(count))

        Next


    End Sub
    Sub Main()

        Dim pointers(12) As Byte, data(12) As String
        Dim startrec, records As Byte
        records = 0
        enterdata(data, pointers, startrec, records)
        printlist(data, pointers, startrec, records)
        enterdata(data, pointers, startrec, records)
        printlist(data, pointers, startrec, records)
        Console.ReadLine()
    End Sub
End Module 
you dont get an element with "list_data(i)", you have to use "list_data[i]"
At array starts at zero and ends at size-1 (i.e. array[0] to array[size-1])
Topic archived. No new replies allowed.