The things I am suppose to do with this program is:
declare a 12-element, one-dimension int array named days.Assign the number of days in each month to the array. (Use 28 days for Feb.)
It is suppose to be coded so that it displays (on the screen) the number of days in the month corresponding to the number entered by the user. For example, when the user enters the number 1, the program should display 31 on the screen. The program should display an appropriate message when the user enters an invalid number.
When I compile it, I get no errors, its just when I run it, I dont get the right output. Can someone please lead into the right direction.
Thanks!
//Ch11AppE02.cpp
//Displays the number of days in a month
//Created/revised by <your name> on <current date>
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int main()
{
//declare variables and arrays
int month = 0;
int days[12]={31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
//get user input
cout << "Enter the month's number(1-12): " << endl;
cin >> month;
//displays error message for invalid input
cout << "Invalid input" << endl;
//ask the user to enter data again
cout << "Enter the month's number(1-12): " << endl;
cin >> month;
//accumulates the month
for (int x = 0; x < 12; x= x + 1)
//end for
//display the days in that month
cout << "That month has the following days: " << days[x] << endl;
return 0;
} //end of main function
My output that I get:
Enter the month's number(1-12):
1
Invalid input
Enter the month's number(1-12):
1
That month has the following days: 31
That month has the following days: 28
That month has the following days: 31
That month has the following days: 30
That month has the following days: 31
That month has the following days: 30
That month has the following days: 31
That month has the following days: 31
That month has the following days: 30
That month has the following days: 31
That month has the following days: 30
That month has the following days: 31
Press any key to continue . . .


Sign In
Create Account


Back to top










