Hello, I am in need of help with a function. I wrote this program in order to display the number of days in a month according to my 12 element array. I wrote it using an if else statement, however, I have to alter it into a function named "displayMonthDays". The output should look like this "Month #2 has 28 days."
This is the program before any alterations:
#include <iostream>
using namespace std;
int main()
{
int num;
int days[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
Well you're not far off, assuming you're working from your #include <iostream> and down.
First thing your function declaration is off, your actual implementation has displayMonthDays taking two parameters, your first declaration has it taking in one, so that should be changed to: void displayMonthDays(int days[], int num);
Second, when you call your function you're only passing it num, when you need to pass it the array AND num, so: displayMonthDays(days, num);
And lastly you don't need to increment num by 1 right before your function call so you might want to take out the num += 1; line