Trying to complete a program that displays number of days in a month using an array. Need to display the number of days in the month corresponding to the number entered example 1 is 31 and 2 is 28 etc.Here is what I have so far:
int main()
{
//declare array and variable
int daysArray[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
Syntax error:
1 2
//call function
displayDays [int month];
Logic error:
1 2 3 4 5 6 7 8
void displayDays(int month)
{
int month= 0; //this is the parameter, don't declare it again
int daysArray[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
//get month, then display
cout << "Enter number of the month: ";
cin >> month;
You should read input outside the function and pass it as argument
Yeah; Warnis is right. Remember: just because the compiler says the error is on line n; doesn't mean it is. It's very possible that the mistake is on line n - 1 ( the line before n) but the compiler reports it as being on the next line.