Your first if statement was a very good idea! But, you have no else with it, so after it outputted the error it would just try and continue with the program.
But if statements are great things! Perhaps if you work on your syntax some more (more consistent and neater) you would not dislike them so.
The seconds if statement and for loop is completely useless.
Here it is a little better:
Code:
#include <iostream>
using namespace std;
int main()
{
int days_per_month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int user_selection;
cout << "Enter month to display number, Jan = 1, July = 7, ect :";
cin >> user_selection;
if (user_selection > 12 || user_selection < 1) //This is a great if statement you have!
{
cout << "Error: Invalid selection.";
return 1;
}
else
{
cout << "Month " << user_selection << " has " << days_per_month[user_selection-1] << " days." << endl;
}
return 0;
}
}