Function to display array

I need to create a function which takes in the data type of a string array and displays it out


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
#include <iostream>
#include <string>
#include <array>
#include <algorithm>
#include <ctime>

void SortedArray (int x, int size);
void Display (string x[], int size); 
void ageArray (int y[], int size);
void sortedAge (int y[], int size);
void sortedName (string x[], int size);
void sortedUP (string x[], int size);

using namespace std;

int main()
{
	time_t p;
	time(&p);
	cout << ctime(&p) << endl;
	
	int age[5] = { 22, 33, 11, 16, 10 };
	string name[4] = { "Bill", "Adam", "Mary", "David" };

	
	ageArray(age, 5);
	Display(name, 4);
	sortedAge(age, 5);
	sortedName(name, 4);
	sortedUP(name, 4);

	system("PAUSE");
	return 0;

}

void Display(string x[], int size)
{
	for (int i = 0; i < size; i++)
	{
		cout << x[i] << " ";
	}
}



It says that all of the functions declared don't take 2 arguments... when it obviously does from my prototypes.
Last edited on
Need urgent help please
closed account (28poGNh0)
Sooooo simple

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# include <iostream>
using namespace std;

void Display (string x);

int main()
{
	string name[4] = { "Bill", "Adam", "Mary", "David" };

	Display(name[2]);

	return 0;
}

void Display(string x)
{
	cout << x << endl;
}

Now there is a problem with my sort function.

1
2
3
4
5
6
7
8
void sortedName(string x, int size)
{
	sort(x, x+size);
	for (int i = 0; i < size; i++)
	{
		cout << x[i] << " ";
	}
}


Also it says there is a syntax error ')' for prototype Display, sortName, and sort UP

full code:
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
#include <iostream>
#include <string>
#include <array>
#include <algorithm>
#include <ctime>

void SortedArray (int x, int size);
void Display (string x, int size); 
void ageArray (int y[], int size);
void sortedAge(int y[], int size);
void sortedName(string x, int size);
void sortedUP (string x, int size, char z);

using namespace std;

int main()
{
	time_t p;
	time(&p);
	cout << ctime(&p) << endl;
	
	int age[5] = { 22, 33, 11, 16, 10 };
	string name[4] = { "Bill", "Adam", "Mary", "David" };

	char c;
	
	ageArray(age, 5);
	Display(name, 4);
	sortedAge(age, 5);
	sortedName(name, 4);
	sortedUP(name, 4, c);

	system("PAUSE");
	return 0;

}

void Display(string x, int size)
{
	for (int i = 0; i < size; i++)
	{
		cout << x[i] << " ";
	}
}

void ageArray(int y[], int size)
{
	for (int i = 0; i < size; i++)
	{
		cout << y[i] << " ";
	}
}

void sortedAge(int y[], int size)
{
	sort(y, y+size);
	for (int i = 0; i < size; i++)
	{
		cout << y[i] << " ";
	}
}

void sortedName(string x, int size)
{
	sort(x, x+4);
	for (int i = 0; i < size; i++)
	{
		cout << x[i] << " ";
	}
}
closed account (28poGNh0)
you asked for Function to display array not for a sort function.

wait couple mins I'll come back to try solve it
I have separate functions, one to display, the others to sort
Need some help please
What are yu trying to do wth Display(string,int) ?
to display each name in the array Name
Try to change void Display(string,int) to void Display(string[],int)
Topic archived. No new replies allowed.