# arrays and functions

Page 1 of 1

## 2 Replies - 1124 Views - Last Post: 30 November 2010 - 08:08 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=202754&amp;s=7bfbea546bef7005ace3128dd10329b8&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 defunktlemon

Reputation: 0
• Posts: 14
• Joined: 29-November 10

# arrays and functions

Posted 29 November 2010 - 08:02 PM

Hi:
I'm real new to programming and have the following program which is an exercise in using functions and arrays but is not quite working. Could somebody help me understand what is wrong with it and why please?
The program should take an input from the user of two dates, day/month/2010, and return a value of the number of days between them.

Program:

```/*Program to read user input of two dates and return the number of days between them*/
#include <stdio.h>

int month_days[12] = {31, 29, 30, 30, 31, 30, 31, 31, 30, 31, 30, 31}; //declare array and assign number of variables...

int monthdays(int m1, int m2)//formal parameters...
{
int numDays=0;
//...compute correct numDays here
for(i=m1-1; i<=m2-1; i++)
numDays = numDays + m1[i];

return numDays;
}

int main()
{
int days, month_1 = 0, month_2 = 0, months_between = 0; //declare integer variable...

int numOfDays;

printf("Please input a number between 1 and 12 for the month: \n");
scanf("%d", &month_1);
printf("Now input a number between 1 and 12 for the second month: \n");
scanf("%d", &month_2);

months_between = month_2 - month_1;
printf("The number of months between them are: %d\n", months_between);

numOfDays = monthdays(month_1, month_2);//actual parameters...
printf("The number of days between them are: %d\n", numOfDays);

return 0;
}

```

Thank you

Is This A Good Question/Topic? 0

## Replies To: arrays and functions

### #2 Maxwellius

Reputation: 0
• Posts: 4
• Joined: 29-November 10

## Re: arrays and functions

Posted 29 November 2010 - 08:27 PM

In the function monthdays, you declare that m1 and m2 are integers, yet you use m1 as an integer array.

### #3 defunktlemon

Reputation: 0
• Posts: 14
• Joined: 29-November 10

## Re: arrays and functions

Posted 30 November 2010 - 08:08 PM

Hi Maxwellius: