Passing arrays into functions?

I'm having trouble with passing arrays into functions, can anyone tell me whats wrong with the code here?

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
  #include <iostream>
#include <conio.h>
#include <time.h>
using namespace std;
const int size = 50;
void sort(int, int, int);
int main()
{
	int amount, year;
	int month, day;
	char slash = '/';
	int months[size], days[size];
	cout << "Enter the amount of digits you wish to enter.";
	cin >> amount;
	cout << "now enter the year you wish to use.";
	cin >> year;
	for(int i=0; i<amount;i++)
	{
		
		month = rand() % 12+1;
		months[i]=month;
		if (month == 4 || month == 6 || month == 9 || month == 11)
		{
			day = rand() % 30+1;
			
		}//end of if(first if ) bracket 
		else if (month == 2){
			if (year%4==0 && year%100>0 || year%400 == 0)
				{
					day=rand()% 29+1;
				}// end of if bracket of else if
			else 
				day = rand()% 28+1;
		}// end of else if bracket for feb
		else 
			day=rand()%31+1;
		days[i]=day;
		cout << month << slash << day << endl;
	}// end of for bracket
	sort(months[size], days[size], size);
}// end of main bracket

void sort(int months[size],int days[size], int amount)
{
	int temp;
	for (int i=0;i<=amount;i++)
	{
		temp=months[i];
		if (months[i]<months[i+1])
		{
			months[i]=months[i];		

		}//end of if 
		else 
		months[i]=months[i+1];
			
	}// end of for loop

}



There are few things which looks incorrect , some things I noticed are:
1) conio.h is not part of c++ standard
2) calling sort function syntax does not look right

You can refer this link which further talks about passing array into functions
http://stackoverflow.com/questions/14309136/passing-arrays-to-function-in-c
Last edited on
Thank you so much that was exactly what I needed actually :)
Topic archived. No new replies allowed.